如何改变横向模式

时间:2010-08-17 04:07:53

标签: iphone

嗨,我是iphone新手。我正在做的是显示图片网格视图。我需要的是我必须从肖像模式将我的模拟器更改为横向模式。在旋转模拟器时,图像不会旋转。我如何旋转图像以及simulator.pls发布所有模式的一些代码

1 个答案:

答案 0 :(得分: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;
}
希望它对你有用。