Auto Rotate To Different View?

Discussion in 'iOS Programming' started by iLoveDeveloping, Jan 27, 2010.

  1. iLoveDeveloping macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #1
    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..
     
  2. boyplunder macrumors regular

    boyplunder

    Joined:
    Sep 8, 2008
    Location:
    UK
    #2
    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.
     
  3. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #3

    Are you talking about the Auto resizing tools in IB?
     
  4. boyplunder macrumors regular

    boyplunder

    Joined:
    Sep 8, 2008
    Location:
    UK
    #4
    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.
     
  5. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #5
    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... :(
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    You could always look into presenting a new view inside willRotateToInterfaceOrientation:duration: or didRotateFromInterfaceOrientation:
     
  7. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #7
    So would i write that like so?

    Code:
     - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientationLandscapeLeft)toInterfaceOrientation duration:(1)duration
    
    
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    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
        }
    }
     
  9. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #9
    Cool, thanks, i'll try give that a go and see can i get something going...
     
  10. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #10
    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?
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    Are you expecting the app to start up in landscape mode?

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

    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.
     
  12. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #12
    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.
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    Hmm, why not?

    EDIT: iLoveDeveloping, seems to be less "quirks" if you override the didRotateFromInterfaceOrientation: method instead.
     
  14. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #14
    Seems weird.

    I haven't tried it. If it gives you what you want then ok.
     
  15. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #15
    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?
     
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    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.

    Didn't boyplunder suggest something like this already?
     
  17. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #17
    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... :)
     
  18. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #18
    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.
     
  19. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #19
    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?

    Much thanks!
     
  20. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #20
    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"
     
  21. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #21
    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!
     
  22. Michael H macrumors newbie

    Joined:
    Jan 26, 2008
    #22
    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.
     
  23. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #23
    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.
     
  24. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #24

    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)
     

Share This Page