Question

I am creating an iOS app that creates layouts directly in code. I am used to using xib, but that is not an option for this project. I cannot figure out how to position an element fixed to the bottom/side of the screen. The solution I'm looking for will position it to the bottom in portrait, but on rotation will fix it to the right hand side (very similar to how the bottom bar works in the camera app). It's properly at the bottom of the screen in portrait, the problem is on rotate

Also I'm building for iOS 5 so I need a solution that does not use Auto-Layout.

Here is the code I have so far that I do on rotate to landscape. The idea is that I rotate 90(which is working) then use some sort of mask to anchor it to the left hand side. Where am I going wrong here? Is it even possible to anchor an object like this??

myView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleLeftMargin;


CGAffineTransform rotate90 = CGAffineTransformMakeRotation(degreesToRadians(-90));

myView.transform = rotate90;

Example Sketch

Was it helpful?

Solution

Do not deal with the bar, but with the views inside your bar.

Try this :

1) Prevent your app from autoRotate using :

//For iOS 5 and lower
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return NO;
}

//For iOS 6 and upper
- (BOOL)shouldAutorotate {
    return NO;
}

2) Rotate the view inside your bar and not your bar itself

Hope it will help you.

OTHER TIPS

You need to use the NSLayoutConstraints for doing this.

I don't know much about the constraints coding, so please refer NSLayoutConstraint for more reference.

WWDC 2012 Session Videos about NSLayoutConstraints

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top