久久久久久久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 創建圖像)
主站蜘蛛池模板: 国产视频中文字幕 | 国产精品一区二 | 日韩视频三区 | 亚洲国产高清高潮精品美女 | 久久99精品久久久水蜜桃 | 亚洲精品在线免费看 | 欧美性受xxxx | 91精品国产91久久久 | 国产精品久久久久久久久久三级 | 日韩网| 欧美激情亚洲激情 | 久久精品国产免费一区二区三区 | 在线国产一区 | 国产精品99久久久久久久vr | 欧美国产亚洲一区二区 | 欧美一区二区三区在线观看 | 欧美极品少妇xxxxⅹ免费视频 | 午夜精品福利视频 | 91精品国产91久久综合桃花 | 国产成人99久久亚洲综合精品 | 一级在线视频 | 午夜男人天堂 | 在线观看电影av | 91国产精品 | 久久精品国产亚洲一区二区 | 欧美极品一区二区 | 精品国产一区久久 | 秋霞国产| 九九色综合 | 亚洲国产91 | 91视频在线 | 日韩精品视频网 | 97精品国产一区二区三区 | 午夜天堂精品久久久久 | 成人毛片网站 | 男人天堂网站 | 精品99久久 | 欧洲性生活视频 | 欧美成人a∨高清免费观看 色999日韩 | 欧美一级高清片 | 亚洲午夜在线 |