久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

UIScrollView 在 contentSize 改變時調整 contentOffset

UIScrollView adjusts contentOffset when contentSize changes(UIScrollView 在 contentSize 改變時調整 contentOffset)
本文介紹了UIScrollView 在 contentSize 改變時調整 contentOffset的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在調整詳細視圖控制器的狀態,就在它被推送到 navigationController 之前:

I am adjusting a detail view controller's state, just before it is pushed on a navigationController:

[self.detailViewController detailsForObject:someObject];
[self.navigationController pushViewController:self.detailViewController
                                     animated:YES];

DetailViewController 中有一個滾動視圖.我根據傳遞的對象調整了哪些內容的大小:

In the DetailViewController a scrollView resides. Which content I resize based on the passed object:

- (void)detailsForObject:(id)someObject {
    // set some textView's content here
    self.contentView.frame = <rect with new calculated size>;

    self.scrollView.contentSize = self.contentView.frame.size;
    self.scrollView.contentOffset = CGPointZero;
}

現在,這一切正常,但是在 navigationController 的滑入動畫期間,scrollView 會調整它的 contentOffset.contentOffset 將設置為最后一個 contentSize 和新計算的值之間的差異.這意味著第二次打開 detailsView 時,詳細信息將滾動到某個不需要的位置.即使我將 contentOffset 明確設置為 CGPointZero.

Now, this all works, but the scrollView adjusts it's contentOffset during the navigationController's slide-in animation. The contentOffset will be set to the difference between the last contentSize and the new calculated one. This means that the second time you open the detailsView, the details will scroll to some unwanted location. Even though I'm setting the contentOffset to CGPointZero explicitly.

我發現在-viewWillAppear中重置contentOffset沒有效果.我能想到的最好辦法是重置 viewDidAppear 中的 contentOffset,導致內容明顯上下移動:

I found that resetting the contentOffset in - viewWillAppear has no effect. The best I could come up with is resetting the contentOffset in viewDidAppear, causing a noticeable up and down movement of the content:

- (void)viewDidAppear:(BOOL)animated {
    self.scrollView.contentOffset = CGPointZero;
}

有沒有辦法防止 UIScrollView 在其 contentSize 更改時調整其 contentOffset?

Is there a way to prevent a UIScrollView from adjusting its contentOffset when its contentSize is changed?

推薦答案

在使用 UINavigationController 推送包含 UIScrollViewUIViewController 時發生.

Occurs when pushing a UIViewController containing a UIScrollView using a UINavigationController.

iOS 11+

解決方案 1(Swift 代碼):

scrollView.contentInsetAdjustmentBehavior = .never

解決方案 2(故事板)

iOS 7

解決方案 1(代碼)

設置 @property(nonatomic, assign) BOOL automaticallyAdjustsScrollViewInsetsNO.

解決方案 2(故事板)

取消選中調整滾動視圖插圖

iOS 6

解決方案(代碼)

viewWillLayoutSubviews中設置UIScrollView的屬性contentOffsetcontentInset.示例代碼:

Set the UIScrollView's property contentOffset and contentInset in viewWillLayoutSubviews. Sample code:

- (void)viewWillLayoutSubviews{
  [super viewWillLayoutSubviews];
  self.scrollView.contentOffset = CGPointZero;
  self.scrollView.contentInset = UIEdgeInsetsZero;
}

這篇關于UIScrollView 在 contentSize 改變時調整 contentOffset的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
主站蜘蛛池模板: 超碰成人免费 | 日本精品视频 | 欧美视频 亚洲视频 | 日韩成人影院在线观看 | 成人免费视频 | 国产成人精品综合 | 国产高清一区二区 | 精品在线视频播放 | 亚洲午夜精品 | 国产特级毛片aaaaaa喷潮 | 中文字幕国产一区 | 91视频入口| 成人三级电影 | 青青草在线视频免费观看 | 亚洲高清视频一区二区 | 日韩精品中文字幕在线 | 91精品久久久久久久久 | 国外激情av | 久久综合伊人 | www.av7788.com| 超碰在线久 | 天天干干| 成人午夜影院 | 国产激情一区二区三区 | 亚洲精品一区在线观看 | 网站黄色av | 国产农村妇女精品一区 | 国产精品精品 | 国产在线成人 | 欧美日韩在线不卡 | 久久精品 | 日韩高清在线 | 国产91观看 | 国产在线观看一区二区三区 | www97影院| 久久综合伊人 | av黄色免费在线观看 | 九九成人 | 久久久久久久久久久久91 | 国产高清无av久久 | 亚洲一区二区三区欧美 |