Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iLoveDeveloping

Suspended
Original poster
Sep 24, 2009
596
2,366
Ireland
Hey,

I just installed an auto-rotate on an App im working on, just a simple : -
Code:
 (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

But say the user is looking at information, on the first screen, then they tilt it, and a new view comes up, say showing a picture based on that information. How does one go about doing that? How can you rotate to make something new??

And i have an App that does this, so i know it can be done... Any ideas?

Thanks guys..
 
What you might want to consider is using the rotate anchor controls for that view, so that a different part of the view [A picture?] shows in landscape, but doesn't show in portrait. I found this is possible if you use a larger view size, but set the items on the view to lock to the 'wrong' position when rotated. I had a button and label that sat off the view when rotated, only because I hadn't set the locks properly.

Low tech, but could be put to work in a number of ways.
 
What you might want to consider is using the rotate anchor controls for that view, so that a different part of the view [A picture?] shows in landscape, but doesn't show in portrait. I found this is possible if you use a larger view size, but set the items on the view to lock to the 'wrong' position when rotated. I had a button and label that sat off the view when rotated, only because I hadn't set the locks properly.

Low tech, but could be put to work in a number of ways.


Are you talking about the Auto resizing tools in IB?
 
Yes, that's right. As I said, it is a bit low tech, but I played with it for a while and it works for something you describe. I thought at the time that having a sort of two column layout on the view could work, and only show the first column when in portrait.

I don't know of a way of switching views by changing orientation, but this came to mind when I read your entry.
 
Aw ok, not exactly what i was looking for, but i will play with it a bit to see if i can get anything i can work with! Would rather if there was a better way though, as i have like 50 Views, and resizing them all one by one by hand is just ridiculous... :(
 
You could always look into presenting a new view inside willRotateToInterfaceOrientation:duration: or didRotateFromInterfaceOrientation:
 
You could always look into presenting a new view inside willRotateToInterfaceOrientation:duration: or didRotateFromInterfaceOrientation:

So would i write that like so?

Code:
 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientationLandscapeLeft)toInterfaceOrientation duration:(1)duration
 
So would i write that like so?

Code:
 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientationLandscapeLeft)toInterfaceOrientation duration:(1)duration
No. These are methods that you override in your UIViewController subclass. So more like:
Code:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        // present a new view
    }
}
 
No. These are methods that you override in your UIViewController subclass. So more like:
Code:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        // present a new view
    }
}

Cool, thanks, i'll try give that a go and see can i get something going...
 
ok, that isn't doing anything at all when i launch the App. I'm probably doing it wrong? I have this in the code..

Code:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
		[self presentModalViewController:testViewController animated:YES];
    }
}

Yes / No? What am i doing wrong?
 
ok, that isn't doing anything at all when i launch the App.
Are you expecting the app to start up in landscape mode?

I have this in the code..

Code:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
		[self presentModalViewController:testViewController animated:YES];
    }
}

Yes / No?
That looks fine, assuming testViewController is an instance variable and instantiated prior to this code being called.

What am i doing wrong?
Have you made sure you've overridden shouldAutorotateToInterfaceOrientation: as well?

Maybe try putting a NSLog or breakpoint into willRotateToInterfaceOrientation:duration: to ensure it's being called.
 
If you want to change the appearance during or after a rotation you most likely want to addSubview your new view and removeSubviewFromSuperview your old view. Could possibly just change the alpha of these views to make them hide and show, instead.

I wouldn't try to presentModal during a rotation.
 
This is just really not working! its doing nothing! Is there any way i can change a view when rotated? Say it looks one way portrait and looks a different way when turned to landscape? Maybe that might work?
 
This is just really not working! its doing nothing!
Well, without seeing your code, I can't really tell why not. And how is it not working? Is the view not even rotating? Did you follow my advice and put an NSLog or breakpoint into some of the rotation methods to try and troubleshoot? I know my approach can work because I've done it.

Is there any way i can change a view when rotated? Say it looks one way portrait and looks a different way when turned to landscape? Maybe that might work?
Didn't boyplunder suggest something like this already?
 
Ok, so after a day of messing around i have a lot of it worked out! I can change the view and present a new view when tilted! But im working on which way it should tilt now.. I was wondering, can i write this in the code?

Code:
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
	
}

Cos it seems to not be working? Am i missing something? Its not turning left AND right. (well, to make myself more clear, its turning Left perfectly, but when i tilt it right the View is upside down and wont rotate to me.)

Basically i want to tilt the View have it 'present' TestViewController, BUT i ONLY want TestViewController to be viewable either left or right! NOT PORTRAIT...



Hope you can understand all that! been working on this a while now so its all mapped in my head, hard to describe it... :)
 
...I was wondering, can i write this in the code?
Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
	
}
I'm sorry but it seems pretty obvious from this that you still have refrained from stepping back from the real coding and going and learning the basics of Objective-C. I'm out.
 
I'm sorry but it seems pretty obvious from this that you still have refrained from stepping back from the real coding and going and learning the basics of Objective-C. I'm out.

Whatever Dejo....... Your like a broken record, you have your view on the subject i have mine, i learn through doing (like many people!?) if you don't like me get over it and stop commenting on my questions then, someone else can help me...



So,
Can anyone help on my earlier problem?

Ok, so after a day of messing around i have a lot of it worked out! I can change the view and present a new view when tilted! But im working on which way it should tilt now.. I was wondering, can i write this in the code?

Code:
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
	
}

Cos it seems to not be working? Am i missing something? Its not turning left AND right. (well, to make myself more clear, its turning Left perfectly, but when i tilt it right the View is upside down and wont rotate to me.)

Basically i want to tilt the View have it 'present' TestViewController, BUT i ONLY want TestViewController to be viewable either left or right! NOT PORTRAIT...

Much thanks!
 
Sorry to disappoint, but I think you should try Dejo's "broken record" advice. Step back and review the basics of -C and maybe you'll figure out whats "wrong with this method"
 
Doesn't matter now, I got it working, I got someone to help me! SOME PEOPLE are nice human beings who want to help people any way they can!

If every teacher in the world told there students "just go read a book and learn it" we'd all be dumb as pig sh**! So excuse me if i like to learn by doing, not reading! I have dyslexia so reading all that code means NOTHING to me... I need to see something working to understand how it works!! Everyone is different so please don't put my in your little generalized box..

@end!
 
Have same problem you had

Hi iLoveDeveloping,

I'm having the same issue. I want to have View1 show in portrait and View2 (a different view) show for landscape. You mentioned you received help and got an answer to this problem but you didn't post the solution.

Would you be kind enough to post solution. "posting a detailed solution is appreciated"

Thanks for your help.
 
Ok, so after a day of messing around i have a lot of it worked out! I can change the view and present a new view when tilted! But im working on which way it should tilt now.. I was wondering, can i write this in the code?

Code:
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
	
}
You CAN write this code, but I don't think it will work the way you are thinking it will.

I'd normally be with dejo on this, but sometimes people have gaps in logic that are not necessarily apparent.

If you write a function like...
Code:
bool fun(int x) {
     return (x == 1);
     return (x == 2);
}
The second return line will never be called. This is analogous to what you wrote. Actually I don't think analogous is the right word. More like strictly equivalent.
 
Hi iLoveDeveloping,

I'm having the same issue. I want to have View1 show in portrait and View2 (a different view) show for landscape. You mentioned you received help and got an answer to this problem but you didn't post the solution.

Would you be kind enough to post solution. "posting a detailed solution is appreciated"

Thanks for your help.


Ignoring the changing view during rotation problem. Can you change your view if you, say, hit a button on one of the views?
If you create a new project and just focus on switching out views with a button press, you will probably see in no time how to change out views on autorotation.

Bonus points for if you use lazy loading to accomplish it. (this will especially help if you decide to destroy one view to save memory)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.