久久久久久久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 創建圖像)
主站蜘蛛池模板: 国产精品一区在线观看 | 久久骚 | 日韩国产一区二区三区 | 国产不卡视频 | 国产精品伦一区二区三级视频 | 中文字幕一区在线 | 亚洲视频在线播放 | 91精品国产色综合久久 | 精品一二三 | 久久免费精品视频 | 婷婷去俺也去 | 日韩中文字幕在线免费 | 成人精品一区二区三区四区 | 精品一区二区在线视频 | 国产午夜精品一区二区三区嫩草 | 蜜桃av人人夜夜澡人人爽 | 中文在线一区二区 | 国产欧美精品一区二区三区 | 欧美日韩一区在线观看 | 亚洲一区二区三区四区五区中文 | 国产一区二区欧美 | 成人精品啪啪欧美成 | 欧美黄a | 国产精品久久国产精品 | 亚洲高清一区二区三区 | 免费国产一区 | 在线观看视频一区 | 成人精品在线观看 | 中文字幕一区在线观看视频 | 亚洲国产精品一区二区久久 | 亚洲天堂av一区 | 欧美a免费 | 香蕉久久a毛片 | 一区二区三区在线免费观看 | 户外露出一区二区三区 | a黄视频 | www.日韩| 国产欧美精品一区二区三区 | 中文在线播放 | 久久久久国产 | 亚洲免费在线观看 |