开发者

how to change landscape mode

开发者 https://www.devze.com 2023-01-11 16:49 出处:网络
hi i am new to iphone.what i am doing is displaying the images grid view. what i need is i have to c开发者_Go百科hange my simulator to landscape mode from portrait mode. while rotating the simulator t

hi i am new to iphone.what i am doing is displaying the images grid view. what i need is i have to c开发者_Go百科hange my simulator to landscape mode from portrait mode. while rotating the simulator the images are not rotated. how can i rotate images along with simulator.pls post some code for all mode


you have to set ,

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

so that you can get all type of orientations. It's better to use reposition your controls according to the orientation. so find the location on screen and set it as given below,

- (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"]];
    }

}

Find right places for control and specify that in CGRectMake function.

Also nil all controls ,

- (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;
}

hope it will work for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消