开发者

Rotation with Different Layouts - iOS 4

开发者 https://www.devze.com 2023-03-01 16:20 出处:网络
The following are the two layouts that I want have in my application.It would be nice if when the application switches from portrait to landscape that it keeps the UILabels, BOOLs, and other objects.

The following are the two layouts that I want have in my application. It would be nice if when the application switches from portrait to landscape that it keeps the UILabels, BOOLs, and other objects. Because the buttons are situated differently I cannot just have the portrait view autoresize on an auto rotate. I also want to implement my own rotation lock using a BOOL and the button on the top right.

I thought about using a -(void)orientationChanged:(NSNotification )notification with a presentModalViewController however these didn't copy over the objects and seemed to cause more harm then good and didn't appear to work properly.

Thanks for the help!

Rotation with Different Layouts - iOS 4

Rotation with Different Layouts - iOS 4

Attempted Solutions:

I added the landscape view to the ViewController, having both views in the view controller. I linked it up to File's Owner under the UIView *landscapeView that I added in the @interface section of the ViewController. I added [self.view addSubview:landscapeView] to the viewDidLoad method. Then I added this piece of code:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (orientationLock)
        return NO;
    else {
        if (interfaceOrientation == UIInterfaceOrientationPortrait) {
            [landscapeView setHidden:YES];
            //[self.view setHidden:NO]; removed
        } else {
            //[self.view setHidden:YES]; removed
            [lan开发者_开发问答dscapeView setHidden:NO];
        }
        return YES;
    }
}

However this is not the correct solution. When I run the simulator and rotate it, the screen is not properly placed.

Rotation with Different Layouts - iOS 4


All things(your instance variables values) remains same when the device changes orientation. If you have only one viewController and you are showing both orieantation in the same then you can easily manage this. I suggest you to create two UIViews in the nib file that way you can do all the things you want.Hope you understand what I am talking about.Let me know if you need help.

Here is modified code

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (orientationLock)
    return NO;
else {
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        [landscapeView setHidden:YES];

    } else {

        [landscapeView setHidden:NO];
    }
    return YES;
}
}
0

精彩评论

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