IOS纯手写代码支持旋屏
2013-10-29 22:43
387 查看
不用ib纯手写代码实现旋屏效果,xcode4.6.3,今天试了一下,可以做到,但是代码量会增加,基本思路是:在
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {}函数中判断toInterfaceOrientation根据这个判断来重新布局,因为每旋转一下都会进这个方法,具体代码如下,只针对3.5寸屏幕,如果换成4寸又得增加大量代码
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"11111111");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
UIButton *btn = (UIButton *)[self.view viewWithTag:101+i];
btn.frame = CGRectMake(5+(460-5-100-5)*i, 5+(320 -5-50-5)*j, 100, 50);
[self.view addSubview:btn];
[btn setTitle:@"11111" forState:UIControlStateNormal];
}
}
for (int i = 0 ; i < 3; i++) {
UIButton *btn = (UIButton *)[self.view viewWithTag:201+i];
btn.frame = CGRectMake(5+105*i, 320/2 - 50/2, 100, 50);
[self.view addSubview:btn];
[btn setTitle:@"2222" forState:UIControlStateNormal];
}
}
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
NSLog(@"222222222");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
UIButton *btn = (UIButton *)[self.view viewWithTag:101+i];
btn.frame = CGRectMake(5+(320-5-100-5)*i, 5+(460 -5-50-5)*j, 100, 50);
[self.view addSubview:btn];
[btn setTitle:@"11111" forState:UIControlStateNormal];
}
}
for (int i = 0 ; i < 3; i++) {
UIButton *btn = (UIButton *)[self.view viewWithTag:201+i];
btn.frame = CGRectMake(5+105*i, 460/2 - 50/2, 100, 50);
[self.view addSubview:btn];
[btn setTitle:@"2222" forState:UIControlStateNormal];
}
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {}函数中判断toInterfaceOrientation根据这个判断来重新布局,因为每旋转一下都会进这个方法,具体代码如下,只针对3.5寸屏幕,如果换成4寸又得增加大量代码
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"11111111");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
UIButton *btn = (UIButton *)[self.view viewWithTag:101+i];
btn.frame = CGRectMake(5+(460-5-100-5)*i, 5+(320 -5-50-5)*j, 100, 50);
[self.view addSubview:btn];
[btn setTitle:@"11111" forState:UIControlStateNormal];
}
}
for (int i = 0 ; i < 3; i++) {
UIButton *btn = (UIButton *)[self.view viewWithTag:201+i];
btn.frame = CGRectMake(5+105*i, 320/2 - 50/2, 100, 50);
[self.view addSubview:btn];
[btn setTitle:@"2222" forState:UIControlStateNormal];
}
}
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
NSLog(@"222222222");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
UIButton *btn = (UIButton *)[self.view viewWithTag:101+i];
btn.frame = CGRectMake(5+(320-5-100-5)*i, 5+(460 -5-50-5)*j, 100, 50);
[self.view addSubview:btn];
[btn setTitle:@"11111" forState:UIControlStateNormal];
}
}
for (int i = 0 ; i < 3; i++) {
UIButton *btn = (UIButton *)[self.view viewWithTag:201+i];
btn.frame = CGRectMake(5+105*i, 460/2 - 50/2, 100, 50);
[self.view addSubview:btn];
[btn setTitle:@"2222" forState:UIControlStateNormal];
}
}
}
相关文章推荐
- iOS开发-小知识(二)
- IOS7 新特性(针对同样讨厌更新后IOS7的开发者)
- 浏览器中打开IOS应用并传参
- iOS开发-各种动画效果
- iOS图片的下载
- ios7 set status bar
- Can all flash games be readily ported to adobe air for deployment on ios
- 2.目录:疯子讲iOS课程
- iOS 使用Quartz 2D画虚线
- Porting from Flash to iOS
- IOS异步下载
- iOS开发同步下载
- Porting a "classic" Flash game to iOS
- IOS 之 动画 知识
- iOS5 ARC学习笔记
- IOS: Clearing an Interface Configuration
- ios版本监测与更新
- Nagios Windows客户端NSClient++ 0.4.x安装配置
- [转]常见的动画效果(二)
- 动画学习1 Animating Views with Blocks