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

UIScrollView 在 contentSize 改變時調(diào)整 contentOffset

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

問題描述

我正在調(diào)整詳細(xì)視圖控制器的狀態(tài),就在它被推送到 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 中有一個滾動視圖.我根據(jù)傳遞的對象調(diào)整了哪些內(nèi)容的大小:

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;
}

現(xiàn)在,這一切正常,但是在 navigationController 的滑入動畫期間,scrollView 會調(diào)整它的 contentOffset.contentOffset 將設(shè)置為最后一個 contentSize 和新計(jì)算的值之間的差異.這意味著第二次打開 detailsView 時,詳細(xì)信息將滾動到某個不需要的位置.即使我將 contentOffset 明確設(shè)置為 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.

我發(fā)現(xiàn)在-viewWillAppear中重置contentOffset沒有效果.我能想到的最好辦法是重置 viewDidAppear 中的 contentOffset,導(dǎo)致內(nèi)容明顯上下移動:

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 更改時調(diào)整其 contentOffset?

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

推薦答案

在使用 UINavigationController 推送包含 UIScrollViewUIViewController 時發(fā)生.

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

iOS 11+

解決方案 1(Swift 代碼):

scrollView.contentInsetAdjustmentBehavior = .never

解決方案 2(故事板)

iOS 7

解決方案 1(代碼)

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

解決方案 2(故事板)

取消選中調(diào)整滾動視圖插圖

iOS 6

解決方案(代碼)

viewWillLayoutSubviews中設(shè)置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;
}

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

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

相關(guān)文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點(diǎn)擊手勢獲取索引或標(biāo)簽值)
UIScrollView not scrolling regardless of large contentSize(無論內(nèi)容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉(zhuǎn)轉(zhuǎn)換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創(chuàng)建圖像)
主站蜘蛛池模板: 久久免费高清视频 | 中文字幕综合网 | 免费黄色片视频 | 中文字幕av在线播放 | 欧美日韩一二区 | 四虎欧美 | 亚洲最大黄色网址 | 日韩中文字幕在线观看 | 三上悠亚激情av一区二区三区 | 欧美黄色片在线观看 | 欧美日韩亚洲综合 | 欧美专区在线观看 | 性生活视频网站 | 久青草视频 | 欧美操| 刘玥大战28公分黑人 | 欧美福利视频 | 日韩国产一区二区 | 久久久久久国产精品 | 青青草久草 | 日本黄色视 | 欧美大片一区二区 | 97在线免费| 免费黄色一级 | 麻豆av在线免费观看 | 五月婷视频 | 久久久在线视频 | 国产区一区二区 | 亚洲一二区 | 国产毛片在线 | 色综合一区 | 日韩网站在线观看 | 日本黄色a级片 | 久操不卡 | www.夜夜操 | 中文字幕日韩一区 | 中文字幕日韩一区 | 成人精品免费 | 日韩一区二区在线播放 | 99精品久久久 | 国产日韩一区二区 |