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

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條評論
主站蜘蛛池模板: 欧美综合亚洲图片综合区 | 免费观看男女羞羞的视频网站 | 四虎影视在线永久免费观看 | 免费国产成人高清在线观看麻豆 | 国产嘿咻视频 | 曰本一级毛片免费 | 久久久久久综合七次郎 | 欧美一级毛片高清毛片 | 黄色一级网 | 99国产精品免费视频 | 亚洲日本高清成人aⅴ片 | 久久怡红院国产精品 | 亚洲午夜精品 | 黄色成人在线 | 免费人成激情视频在线看 | 综合色区| 精品国产区一区二区三区在线观看 | 国产成人夜间影院在线观看 | 999精品视频 | 国产毛片久久精品 | 99在线精品视频免费观里 | 天堂一区二区三区在线观看 | 欧美色操 | 欧美日韩一本大道香蕉欧美 | 亚洲xoxo| 成人性色生活影片 | 国产精品一区在线观看 | 九九热在线免费观看 | 成人免费毛片网站 | 亚洲码欧美码一区二区三区 | 精品999视频| 日本最新免费二区三区 | 在线观看麻豆国产精品 | 色www 永久免费网站 | 国产亚洲精品久久久久久小说 | 国产成人精品一区二三区在线观看 | 四虎永久在线精品国产馆v视影院 | 久久天天躁综合夜夜黑人鲁色 | 亚洲一区二区三区日本久久九 | 日韩美女va在线毛片免费知 | 亚洲香蕉网综合久久 |