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

viewWillAppear: 和 viewDidAppear: 之間的視圖框架變化

View frame changes between viewWillAppear: and viewDidAppear:(viewWillAppear: 和 viewDidAppear: 之間的視圖框架變化)
本文介紹了viewWillAppear: 和 viewDidAppear: 之間的視圖框架變化的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我在我的應(yīng)用程序中發(fā)現(xiàn)了一個(gè)奇怪的行為,其中連接的 IBOutlet 在我的視圖控制器中對(duì) viewWillAppear: 的調(diào)用之間具有其連接的視圖框架viewDidAppear:.這是我的 UIViewController 子類中的相關(guān)代碼:

I have discovered a strange behavior in my application, where a connected IBOutlet has its connected view's frame between the calls in my view controller to viewWillAppear: and viewDidAppear:. Here is the relevant code in my UIViewController subclass:

-(void)viewWillAppear:(BOOL)animated {
    NSLog(@"%@", self.scrollView);
}

-(void)viewDidAppear:(BOOL)animated {
    NSLog(@"%@", self.scrollView);
}

以及生成的日志輸出:

MyApp[61880:c07] <UIScrollView: 0x1057eff0; frame = (0 0; 0 0); clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x10580100>; layer = <CALayer: 0x1057f210>; contentOffset: {0, 0}>
MyApp[61880:c07] <UIScrollView: 0x1057eff0; frame = (0 44; 320 416); clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x10580100>; layer = <CALayer: 0x1057f210>; contentOffset: {0, 0}>

這清楚地表明框架在兩次調(diào)用之間發(fā)生了變化.我想在 viewDidLoad 方法中對(duì)視圖進(jìn)行設(shè)置,但如果內(nèi)容在屏幕上之前無(wú)法更改,那似乎毫無(wú)用處.會(huì)發(fā)生什么?

Which clearly shows that the frame is changing between the two calls. I wanted to do setup with the view in the viewDidLoad method, but if the content is not available for me to change until it is on the screen, that seems pretty useless. What could be happening?

推薦答案

Autolayout 對(duì)我們?cè)O(shè)計(jì)和開(kāi)發(fā)視圖 GUI 的方式進(jìn)行了巨大改變.主要區(qū)別之一是 autolayout 不會(huì)立即更改我們的視圖大小,而是僅在觸發(fā)時(shí),即在特定時(shí)間,但我們可以強(qiáng)制它立即重新計(jì)算我們的約束或標(biāo)記它們作為布局的需要".它的工作方式類似于 -setNeedDisplay.
對(duì)我來(lái)說(shuō)最大的挑戰(zhàn)是要理解并接受這一點(diǎn),我們不再需要使用自動(dòng)調(diào)整大小的蒙版,而框架在放置我們的視圖時(shí)已成為無(wú)用的屬性.我們不再需要考慮視圖位置,但我們應(yīng)該考慮我們希望如何在彼此相關(guān)的空間中看到它們.
當(dāng)我們想要混合舊的自動(dòng)調(diào)整大小蒙版和自動(dòng)布局時(shí),就會(huì)出現(xiàn)問(wèn)題.我們應(yīng)該盡快考慮自動(dòng)布局的實(shí)現(xiàn),并盡量避免在基于自動(dòng)布局的視圖層次結(jié)構(gòu)中混合舊方法.
擁有一個(gè)僅使用自動(dòng)調(diào)整大小掩碼的容器視圖是可以的,例如視圖控制器的主視圖,但如果我們不嘗試混合使用會(huì)更好.
我從未使用過(guò)故事板,但很可能它是正確的.使用自動(dòng)布局,您的視圖框架在自動(dòng)布局引擎開(kāi)始計(jì)算時(shí)設(shè)置.嘗試在視圖控制器的 - (void)viewDidLayoutSubviews 方法的 super 之后詢問(wèn)同樣的問(wèn)題.
當(dāng)自動(dòng)布局引擎完成計(jì)算視圖的幀時(shí)調(diào)用此方法.

Autolayout made a huge change in how we design and develop the GUI of our views. One of the main differences is that autolayout doesn't change our view sizes immediately, but only when is triggered, that means at a specific time, but we can force it to recalculate our constraints immediately or mark them as "in need" of layout. It works like -setNeedDisplay.
The big challenge for me was to understand and accept that, we do not need to use autoresizing masks anymore, and frame has become a useless property in placing our views. We do not need to think about view position anymore, but we should think how we want to see them in a space related to each other.
When we want to mix old autoresizing mask and autolayout is when problems arise. We should think about autolayout implementation really soon and try to avoid to mix the old approach in a view hierarchy based on autolayout.
Is fine to have a container view that uses only autoresizing masks, such as a main view of a view controller, but is better if we do not try to mix.
I never used storyboard, but most proably it is correct. Using Autolayout, frame of your views are set when the autolayout engine starts its calculation. Try to ask the same thing right after super of - (void)viewDidLayoutSubviews method of your view controller.
This method is called when the autolayout engine has finished to calculate your views' frames.

這篇關(guān)于viewWillAppear: 和 viewDidAppear: 之間的視圖框架變化的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫(kù)中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁(yè)面之間的照片應(yīng)用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動(dòng)時(shí)暫停 NSTimer)
主站蜘蛛池模板: 亚洲第一网站 | 久久久久亚洲av毛片大全 | 国产高清免费在线 | www.成人免费视频 | 国产精品久久久久一区二区 | 一区二区三区四区在线视频 | 91中文字幕在线观看 | 国产在线精品一区二区三区 | 日韩av在线一区二区 | 精品国产一区二区三区日日嗨 | 国产99热精品 | 亚洲精品中文字幕 | 天天拍天天操 | 久久久久一区 | 久久亚洲一区二区三区四区 | 资源首页二三区 | 中文成人无字幕乱码精品 | 欧美一级毛片久久99精品蜜桃 | 中文字幕一二三 | 国产精品性做久久久久久 | 国产精品福利一区二区三区 | 国产情侣在线看 | 日韩欧美一区在线 | 午夜视频在线免费观看 | 久久青 | 久久久久久av | 天天爽天天操 | 天天爱av| 激情91 | 很黄很污的网站 | 免费黄色成人 | 日韩亚洲视频 | 国户精品久久久久久久久久久不卡 | 一级黄色淫片 | 日本不卡一区二区三区在线观看 | 国产在线一区二区 | 九九热在线免费视频 | 亚州春色 | 久久综合九九 | 91精品国产综合久久婷婷香蕉 | 国产精品美女久久久久 |