Ios5(三)屏幕的旋转和大小设置;
来源:互联网 发布:消除音乐原声软件 编辑:程序博客网 时间:2024/05/17 02:24
Ios5(三)屏幕的旋转和大小设置;
一. 设置自动转屏的一般原则:
iphone类应用,如果为了增强用户体验,可以增加自动转屏功能,ipad应用,一般都应该添加自动转屏功能;
二. 自动转屏的实现方法:
1. 自动调整;
2. 看到视图旋转提示时,手动调整视图对象位置;
3. 在InterfaceBuilder中为视图设置两个不同的版本,一种为纵向模式,一种是横向模式;
三. 自动调整属性处理:
1. 打开项目设置,看:”Supported Device Orientations”可以更改支持的面向;即更改的info.plist的设置;
2. 在viewController.m文件中,添加方法:系统通过此方法询问视图控制器是否应该旋转到指定方向;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return(toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
3. ios四个方向分别对应的常量:
UIInterfaceOrientationPortraitUpsideDown;
UIInterfaceOrientationPortrait;
UIInterfaceOrientationLandscapeLeft;
UIInterfaceOrientationLandscapeRight;
4. 在xib,加入六个button,查看视图效果
5. 2
四. 旋转时重构视图:
1. 分别将六个按钮关联六个输出口,分别命名为:ul,ur,l,r,ll,lr;
2. 在旋转时重新构图:.m文件中重写方法:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientationduration:(NSTimeInterval)duration{
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
ul.frame =CGRectMake(20,20, 125, 125);
ur.frame =CGRectMake(175,20, 125, 125);
l.frame =CGRectMake(20,168, 125, 125);
r.frame =CGRectMake(175,168, 125, 125);
ll.frame =CGRectMake(20,315, 125, 125);
lr.frame =CGRectMake(175,315, 125, 125);
}else{
ul.frame =CGRectMake(20,20, 125, 125);
ur.frame =CGRectMake(20,155, 125, 125);
l.frame =CGRectMake(177,20, 125, 125);
r.frame =CGRectMake(177,155, 125, 125);
ll.frame =CGRectMake(328,20, 125, 125);
lr.frame =CGRectMake(328,155, 125, 125);
}
}
3. 所有的视图的大小和位置都在frame属性中指定,该属性是一个类型为CGRect的结构;
4. 注意设备朝向的判定,可以用方法,也可以用字段;
五. 旋转时切换视图:
1. 重新建一个单视图项目,并复制视图,分别在两个视图中添加两个那妞,如图:
2. 定义一个角度弧度转换宏:#definedegreesToRadians(x)(M_PI*(x)/180.0)
3. 重现旋转的响应函数:
2- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientationduration:(NSTimeInterval)duration{
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
self.view =portraint;
self.view.transform =CGAffineTransformIdentity;
self.view.transform =CGAffineTransformMakeRotation(degreesToRadians(0));
self.view.bounds =CGRectMake(0.0,0.0, 320.0,460.0);
}else if(UIInterfaceOrientationLandscapeLeft ==toInterfaceOrientation){
self.view =landscape;
self.view.transform =CGAffineTransformIdentity;
self.view.transform =CGAffineTransformMakeRotation(degreesToRadians(-90));
self.view.bounds =CGRectMake(0.0,0.0, 480.0,300.0);
}else{
self.view =landscape;
self.view.transform =CGAffineTransformIdentity;
self.view.transform =CGAffineTransformMakeRotation(degreesToRadians(90));
self.view.bounds =CGRectMake(0.0,0.0, 480.0,300.0);
}
}
4. 添加属性和操作:将两个视图的foo按钮同时关联outlet connection属性foos;Bar关联到bars;
为两个视图的所有按钮关联动作:buttonPressed:
- (IBAction)buttonTapped:(id)sender{
NSString *mes = nil;
if([self.fooscontainsObject:sender]){
mes= @"Foo Button Pressed";
}
else{
mes= @"Bar Button Pressed";
}
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:mesmessage:nildelegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil];
[alert show];
}
IOS有输出口集合功能,可以同时指向多个元素,而输出口只能指向一个元素;
判断:
[self.foos containsObject:sender]返回BOOL值类型;
5. 如果希望点击按钮使两个按钮都消失可以使用数组的快速遍历:
- (IBAction)buttonTapped:(id)sender{
if([fooscontainsObject:sender]){
for(UIButton*onbuttonin foos){
onbutton.hidden = YES;
}
}else{
for(UIButton*onbuttonin bars){
onbutton.hidden = YES;
}
}
}
- Ios5(三)屏幕的旋转和大小设置;
- Ios5(三)屏幕的旋转和大小设置
- 如何同时支持IOS5和IOS6上的屏幕旋转?
- 如何同时支持IOS5和IOS6上的屏幕旋转?
- ios 6 与 ios5 的屏幕旋转
- ios 6 与 ios5 的屏幕旋转
- ios 6 与 ios5 的屏幕旋转
- ios 6 与 ios5 的屏幕旋转
- 关于屏幕旋转设置:iOS5、iOS6及iOS7
- iOS 之屏幕旋转(iOS5和iOS6)
- IOS5基础之四-----自动旋转和调整大小
- 屏幕自动旋转和调节大小
- 屏幕自动旋转和调节大小
- 屏幕自动旋转和调节大小
- 问题解决:iOS6下shouldAutorotateToInterfaceOrientation不起作用,屏幕旋转同时支持iOS5和iOS6
- 问题解决:iOS6下shouldAutorotateToInterfaceOrientation不起作用,屏幕旋转同时支持iOS5和iOS6
- Qt4屏幕旋转和中文字体设置
- ios:(1)iOS 6的Rotation (2)ios 6 与 ios5 的屏幕旋转
- 心情14--2012.11.22
- SVN的分支、主干合并的使用说明
- 一个项目涉及到的50个Sql语句(整理版)
- linux环境下 C++性能测试工具 gprof 和gprof2dot
- Android MMS模块数据存取 (转)
- Ios5(三)屏幕的旋转和大小设置;
- hibernate 各种状态总结
- kthread_run 创建内核线程
- Java基础部分内容考察基础
- LBS游戏火拼三要素:位置、情感、3D渲染
- 中国陆军,傲视群雄
- ruby中Hash的自定义key
- 关于驱动程序中的ioctl
- java元数据