你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS橫屏豎屏問題---2

IOS橫屏豎屏問題---2

編輯:IOS開發綜合
[cpp]   方法一、橫屏豎屏時分別加載兩個不同的view,手寫view   [cpp]   -(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 = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 440)];       portrait.backgroundColor = [UIColor yellowColor];   //    [portrait addButton];                     landscape = [[UIView 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.       NSLog(@"heheh");       return NO;          }   [cpp]   方法二、在一個XIB裡面添加兩個不同的view,只用改變兩個不同view裡面控件尺寸,動作事件是一樣的   [cpp]   -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration   {              if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {           [self.landscapeView removeFromSuperview];           [self.view addSubview:self.portraitView];       }       if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {           [self.portraitView removeFromSuperview];           [self.view addSubview:self.landscapeView];       }   }   - (void)viewDidLoad {       [super viewDidLoad];                     [self.view addSubview:self.portraitView];          }    
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved