[IOS]iphone开发之横屏与竖屏在不同视图之间的切换

有两个视图,横屏视图和纵屏视图,当iphone的方位变化的时候,这两个视图相互切换。

1。两个视图:PortraitView和LandscapeView ,分别标示纵屏和横屏。

2。一个控制器,RootViewController,根控制器。

3。在RootViewController.m中有以下代码

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
[landscape removeFromSuperview];
[self.view addSubview:portrait];
}
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
[portrait removeFromSuperview];
[self.view addSubview:landscape];
}
}


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {

UIControl *back = [[UIControl alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
back.backgroundColor = [UIColor grayColor];
self.view = back;
[back release];

}



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];

portrait = [[PortraitView alloc] initWithFrame:CGRectMake(10, 10, 300, 440)];
portrait.backgroundColor = [UIColor yellowColor];
[portrait addButton];


landscape = [[LandscapeView alloc] initWithFrame:CGRectMake(10, 10, 460, 280)];
landscape.backgroundColor = [UIColor greenColor];

[self.view addSubview:portrait];

}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.

return YES;

}

分析:willAnimateRotationToInterfaceOrientation方法是用于横纵屏变化的时候的切换用。

portrait和landscape是两个视图。

转载于:https://www.cnblogs.com/iphone520/archive/2011/10/14/2211191.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值