2010-08-17 24 views
1

嗨,我是新来iphone.what我在做的是显示图像网格视图。我需要的是我必须将我的模拟器从纵向模式更改为横向模式。在旋转模拟器时,图像不会旋转。我怎么能随simulator.pls张贴一些代码对所有模式如何改变风景模式

+0

模拟器?你的意思是模拟器? – 2010-08-17 04:13:43

+0

对不起,它是模拟器 – MaheshBabu 2010-08-17 04:45:54

回答

1

你必须设置旋转图像,

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return YES; 
} 

,这样你可以得到所有类型的取向。根据方向调整控件的位置会更好。所以发现在屏幕上的位置,并设置为如下,

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration { 

    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
     NSLog(@"login portrait"); 


     okButton.frame = CGRectMake(69, 286, 72, 28); 
     cancleButton.frame = CGRectMake(178, 286, 72, 28); 
     usernameLabel.frame = CGRectMake(92, 140, 149, 16); 
     passwordLabel.frame = CGRectMake(129, 208, 75, 16); 
     usernameField.frame = CGRectMake(69, 164, 181, 31); 
     passwordField.frame = CGRectMake(69, 237, 181, 31); 
     mainLabel1.frame = CGRectMake(35, 58, 250, 21); 
     mainLabel2.frame = CGRectMake(35, 77, 153, 21); 
     [backgroundImage setImage:[UIImage imageNamed:@"portraitLogin.jpg"]]; 
    } else { 
     NSLog(@"login landscape"); 


     signinButton.frame = CGRectMake(190, 183, 86, 27); 
     cancleButton.frame = CGRectMake(309, 183, 86, 27); 
     usernameLabel.frame = CGRectMake(50, 100, 120, 21); 
     passwordLabel.frame = CGRectMake(50, 139, 75, 21); 
     usernameField.frame = CGRectMake(190, 95, 205, 31); 
     passwordField.frame = CGRectMake(190, 134, 205, 31); 
     mainLabel1.frame = CGRectMake(50, 58, 245, 19); 
     mainLabel2.frame = CGRectMake(295, 58, 153, 19); 
     [backgroundImage setImage:[UIImage imageNamed:@"landscapeLogin.jpg"]]; 
    } 

}

查找控制权的地方,并指定在CGRectMake功能。

也无所有控件,

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
    self.usernameLabel = nil; 
    self.usernameField = nil; 
    self.passwordLabel = nil; 
    self.passwordField = nil; 
    self.okButton = nil; 
    self.cancleButton = nil; 
    self.backgroundImage = nil; 
    self.mainLabel1 = nil; 
    self.mainLabel2 = nil; 
} 

希望它会为你工作。