标签:
1.首先在自定义的视图中重写layoutSubviews方法
- (void)layoutSubviews{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation ;//获取屏幕的方向,和状态栏是相同的
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {//横向时的位置
self.button.frame = CGRectMake (300,150,200,40);
} else {
self.button.frame = CGRectMake(150,150,100,40);
}
}
2.在viewController.m文件中
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<
UIViewControllerTransitionCoordinator
>)coordinator{
[self.textField resignFirstResponder];//当屏幕尺寸改变时回收键盘
}
//设置屏幕当前方向
- (NSUInteger)supportedInterfaceOrientation{
return UIInterfaceOrientationMaskAll;
}
标签:
原文地址:http://www.cnblogs.com/arenouba/p/5183299.html