亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

iPhone開發之Rotation

系統 1684 0

?

iPhone或iPad可以支持4種朝向
??? UIInterfaceOrientationPortrait
??? UIInterfaceOrientationPortraitUpsideDown
??? UIInterfaceOrientationLandscapeLeft
??? UIInterfaceOrientationLandscapeRight

究竟支持哪幾個朝向,由view controller的shouldAutorotateToInterfaceOrientation函數來指定,每當設備的朝向發生變化時,這個方法都會被調用。

對于iPhone程序,應該防止用戶在通話時拿倒電話,不支持UIInterfaceOrientationPortraitUpsideDown
因此函數實現為:
- (BOOL)shouldAutorotateToInterfaceOrientation:? (UIInterfaceOrientation) interfaceOrientation {
????? return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
對于iPad,應該支持所有的朝向,因此函數實現為
- (BOOL)shouldAutorotateToInterfaceOrientation:? (UIInterfaceOrientation) interfaceOrientation {
????? return true;
}

實現對Rotation的支持有三種方法:
1. 設置UI元素的Autosize Attribute,類似于.NET form的dock
2. 重新構造UI元素大小和位置
3. 不同的朝向使用不同的view

使用Autosize Attribute

Inner box中的紅色箭頭和UI元素的size有關,如果橫向的紅色的箭頭成為實線,則窗口尺寸變化時UI元素的寬度也會變化,如果橫向紅色箭頭為虛線,則窗口寬度變化時UI元素的寬度保持不變。垂直方向同理。
Inner box周圍的短線變成實線時,表明UI元素和它所在的view的邊緣的距離保持不變。

下圖中的UI對象的高度將會隨著view的高度而變化,同時UI元素相對于View的上下邊距不變

對應的UI設置為

重新構造UI元素的大小和位置

- (void) willAnimateRotationToInterfaceOrientation :? (UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
?? if (interfaceOrientation == UIInterfaceOrientationPortrait
??????? || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
? {
????? button1.frame = CGRectMake(20, 20, 125, 125);
????? button2.frame = CGRectMake(175, 20, 125, 125);
????? button3.frame = CGRectMake(20, 168, 125, 125);
????? button4.frame = CGRectMake(175, 168, 125, 125);
????? button5.frame = CGRectMake(20, 315, 125, 125);
????? button6.frame = CGRectMake(175, 315, 125, 125);
?? }
?? else
?? {
????? button1.frame = CGRectMake(20, 20, 125, 125);
????? button2.frame = CGRectMake(20, 155, 125, 125);
????? button3.frame = CGRectMake(177, 20, 125, 125);
????? button4.frame = CGRectMake(177, 155, 125, 125);
????? button5.frame = CGRectMake(328, 20, 125, 125);
????? button6.frame = CGRectMake(328, 155, 125, 125);
?? }
}

切換View

為了支持兩個View,需要在View controll中生成兩套outlet
@interface SwapViewController : UIViewController {
????? UIView *landscape;
????? UIView *portrait;
????? // Foo
????? UIButton *landscapeFooButton;
????? UIButton *portraitFooButton;
????? // Bar
????? UIButton *landscapeBarButton;
????? UIButton *portraitBarButton;
}
在Interface builder中刪除Xcode自動生成的view,從library中拖兩個view 到main window上。分別命名為Portrait和Landscape.
選中File’s Owner,Control-drag 到Portrait和Landscape,連接outlet

動態加載view
#define degreesToRadians(x) (M_PI * (x) / 180.0)

- (void) willAnimateRotationToInterfaceOrientation : (UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
self.view = self.portrait;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0));#define degreesToRadians(x) (M_PI * (x) / 180.0)
self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
self.view = self.portrait;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);
}
}


iPhone開發之Rotation


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 色爱b | 视频免费1区二区三区 | 最新毛片久热97免费精品视频 | 在线看污网站 | 亚洲美女在线视频 | 国产成人一区二区视频在线观看 | www.黄色一片 | 一区二区三区国产精品 | 成人精品一区二区三区 | 94在线成人免费视频 | 亚洲欧美网址 | 精品中文字幕不卡在线视频 | 国产99对白在线播放 | 天天操天天摸天天碰 | 梦想成为魔法少女在线观看 | 欧美一级特毛片 | 免费一级成人毛片 | 四虎国产精品永久地址49 | 色老头xxxxbbbb视频 | 人人揉揉香蕉大免费不卡 | 黄色成人毛片 | 久久免费观看爱情动作片 | 国产精品中文 | 荷兰毛片 | 国产成人免费不卡在线观看 | 色偷偷亚洲第一成人综合网址 | 淫视频网站 | 欧美成人一区二区三区不卡视频 | 精品日本亚洲一区二区三区 | 美女洗澡一级毛片 | 中文字幕一区视频 | 久久99精品久久久久久噜噜 | 国产精品手机视频 | 97高清国语自产拍免费 | 国产午夜精品福利 | 天天插夜夜 | 精品国产高清自在线一区二区三区 | 99热久久这里只有精品6国产网 | 欧美性猛交xxxxx按摩欧美 | 添bbb免费观看高清视频 | 在线观看深夜观看网站免费 |