当前位置:编程学习 > wap >>

IOS横屏竖屏问题---2

[cpp]  
方法一、横屏竖屏时分别加载两个不同的view,手写view  
[cpp]  
-(void)willAnimateRotationToInte易做图ceOrientation:(UIInte易做图ceOrientation)toInte易做图ceOrientation duration:(NSTimeInterval)duration  
{  
      
    if (UIInte易做图ceOrientationIsPortrait(toInte易做图ceOrientation)) {  
        [landscape removeFromSuperview];  
        [self.view addSubview:portrait];  
    }  
    if (UIInte易做图ceOrientationIsLandscape(toInte易做图ceOrientation)) {  
        [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)shouldAutorotateToInte易做图ceOrientation:(UIInte易做图ceOrientation)inte易做图ceOrientation {  
    // Return YES for supported orientations.  
    NSLog(@"heheh");  
    return NO;  
      
}  
[cpp]  
方法二、在一个XIB里面添加两个不同的view,只用改变两个不同view里面控件尺寸,动作事件是一样的  
[cpp]  
-(void)willAnimateRotationToInte易做图ceOrientation:(UIInte易做图ceOrientation)toInte易做图ceOrientation duration:(NSTimeInterval)duration  
{  
      
    if (UIInte易做图ceOrientationIsPortrait(toInte易做图ceOrientation)) {  
        [self.landscapeView removeFromSuperview];  
        [self.view addSubview:self.portraitView];  
    }  
    if (UIInte易做图ceOrientationIsLandscape(toInte易做图ceOrientation)) {  
        [self.portraitView removeFromSuperview];  
        [self.view addSubview:self.landscapeView];  
    }  
}  
- (void)viewDidLoad {  
    [super viewDidLoad];  
      
      
    [self.view addSubview:self.portraitView];  
      
}  
 
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,