</pre><span style="font-family:'Comic Sans MS'; font-size:18px"></span><p></p><pre name="code" class="objc">
如果你已經下載了xcode5,正準備使用,你會發現各種佈局的改變.
註定這段時間是忙的,是頭疼的!原創在此哦http://my.csdn.net/rhljiayou
這兩天經常會碰到羣裏有人在問問題,問ios7怎麼適配,以及各種網上說的如何解決ios7下狀態欄的問題.
我發現各種羣裏流傳着一種適配方法,就是修改window的座標(window.frame),然後大家紛紛效仿,但是往往出現各種問題,發出各種報怨,各種吐嘈;
殊不知別人的寫法並不是你的寫法,別人的適配也不是你的適配,所以別的方法不一定能解決你的問題.我們要理解他,得到解決思路,而不是解決代碼.
其實官方已經給出狀態欄同時兼容ios6和ios7的解決方案.他就集成在xcode5中,如下圖所示:
着急做適配,可能會做錯喔!原創在此哦http://my.csdn.net/rhljiayou
要了解這個適配先要講一下Deltas也就是這個 ∆,上過高中物理都應該知道這個東西,不認識的請自覺檢討(初中數學就教過).
Deltas的意思你可以理解爲增量.相對增量.
科普講完,下面是具體使用.
首先要出現∆選項,必須使用xcode5的方式打開xib:
在xib的第一個標籤中哦~原創在此哦http://my.csdn.net/rhljiayou
由於我們要同時兼容6和7,所以我們需要選6.1或更早
然後調整增量,增量的意思是如果運行在ios7的模式下,就使其座標+增量,如果是6或更早的,就是直接使用上面的座標
效果如圖,十分完美,呵呵原
<pre name="code" class="objc">
<pre name="code" class="objc">#define iphone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)]?CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size):NO)
#define ios7 [[[UIDevice currentDevice] systemVersion] floatValue] >= 7
#define kTabBarHeight 63.0f
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
self.view.frame=CGRectMake( 0, -50,self.view.frame.size.width, self.view.frame.size.height);
}
UILabel *label1=[[UILabel alloc] initWithFrame:CGRectMake(15,ios7? 45:30,80,40)];
UIView *aView=[[UIView alloc]initWithFrame:
CGRectMake(0, 0, 320,iphone5?600:self.tabBarController.view.frame.size.height)];
以上代碼 視圖大小完美適配。
創在此哦http://my.csdn.net/rhljiayou
-(void)viewWillAppear:(BOOL)animated
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
self.view.bounds =CGRectMake(0, -40,self.view.frame.size.width,self.view.frame.size.height );
}
[super viewWillAppear:animated];
}
<pre>