視圖退出新的視圖控制器:
1.先引入新的試圖控制器的頭文件
2.找到需要與新的視圖連接的button踢关,在其實(shí)現(xiàn)方法中添加下列代碼:
3.創(chuàng)建一個(gè)新的視圖控制器對象:newVC
4.添加[self presentViewController:newVC animated:YES completion:nil];方法
退出新的視圖控制器视哑,返回跟原視圖控制器:
在連接的button的方法中添加如下代碼
[self dismissViewControllerAnimate:YES completion:nil];
屏幕旋轉(zhuǎn)
設(shè)置屏幕的固定方向(無法旋轉(zhuǎn))在視圖控制器中重寫方法
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;//只支持橫屏
}
在屏幕旋轉(zhuǎn)時(shí)處理事件诵叁,如回收鍵盤 ?在視圖控制器中重寫方法
- (void)viewWillTransitionToSize:(CGSize) withTransitionCoordinator:(id)coordinator {
[self.View.textField resignFirstResponder];
}
屏幕旋轉(zhuǎn)時(shí)調(diào)整視圖的位置 在該視圖類中重寫方法(只要視圖本身的bounds發(fā)生變化优俘,此方法就會(huì)被執(zhí)行)
- (void)layoutSubviews {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;//獲取屏幕方向
//判斷是否橫向
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
self.button.frame = CGRectMack( ?, ?, ?, ?);
} ?else {
self.button.frame = CGRectMake( ?, ?, ?, ?);
}
}