Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Interface builder landscape design

superandrewsuperandrew Posts: 5New Users
edited April 2010 in iPhone SDK Development
Hi all, I would design a landscape interface based on UIImageViews, that must be setup in interface builder. I haven't found a way to perform the design in IB.

When i rotate clockwise the interface designer(in IB), I can set up all my images the way I like, then I block programatically the orientation to landscape in Xcode. But when emulator starts, images are rotated 90°!!

I mean, let's say I have an image representing a group of up arrows, in landscape mode. I set the Image in a UIImageView control in IB that I just dragged on the main view. When I rotate the interface designer the arrows still remain in the up direction, but when I start the emulator, the phone turn landscape (that's ok) but the arrows are directed to the left!

The only way I found to do this correctly is to rotate the images with a image editing software, and editing the interface in IB as if the phone is in portrait mode, but this seems to me so stupid!

Thanks for helping, I'm stuck :/

Andrew
Post edited by superandrew on

Replies

  • whathelllwhathelll Posts: 10Registered Users
    edited March 2009
    Hi all, I would design a landscape interface based on UIImageViews, that must be setup in interface builder. I haven't found a way to perform the design in IB.

    When i rotate clockwise the interface designer(in IB), I can set up all my images the way I like, then I block programatically the orientation to landscape in Xcode. But when emulator starts, images are rotated 90°!!

    I mean, let's say I have an image representing a group of up arrows, in landscape mode. I set the Image in a UIImageView control in IB that I just dragged on the main view. When I rotate the interface designer the arrows still remain in the up direction, but when I start the emulator, the phone turn landscape (that's ok) but the arrows are directed to the left!

    The only way I found to do this correctly is to rotate the images with a image editing software, and editing the interface in IB as if the phone is in portrait mode, but this seems to me so stupid!

    Thanks for helping, I'm stuck :/

    Andrew


    did you ever get this figured out? i am having the same issue...
  • bharath2020bharath2020 Posts: 151Registered Users
    edited March 2009
    May be you can override the layoutSubviews method of the parent view and do not invoke super class's method..

    Just taking a wild guess.. let us know the results
    Bharath<br />
    iOS Blog : <a href="http://iphone2020.wordpress.com" target="_blank">http://iphone2020.wordpress.com</a>;
  • BenODwyerBenODwyer Posts: 115Registered Users
    edited March 2009
    I do this by making the IB interface with the window rotated using the small arrow top right of every view.

    Then in my view controller .m I put:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    	[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft];
    	return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }
    

    Then in my Info.plist file add a line and put UIInterfaceOrientation with the value UIInterfaceOrientationLandscapeLeft.

    The above obviously rotates to LandscapeLeft. You could change this to LandscapeRight!

    Hope that helps. Works every time for me!

    Ben
  • superandrewsuperandrew Posts: 5New Users
    edited March 2009
    whathelll wrote: »
    did you ever get this figured out? i am having the same issue...

    If I remember correctly, I used to rotate all the images using an CGAffineTransformMakeRotation and passing a radians-equivalent of 90 degrees. Actually I don't have any snippet of code, let me tell you if you need it so I can post it.

    Andrea Maschio
    http://www.2manyclicks.com
  • whathelllwhathelll Posts: 10Registered Users
    edited March 2009
    i have the autorotate in every controller class.

    the main xib displays correctly but the secondary xib called from the first is off by 90 degrees... do i need to add things to the plist for every xib or any way to pass down properties from the main xib to the secondary xibs?
  • BenODwyerBenODwyer Posts: 115Registered Users
    edited March 2009
    In my app I have a main view controller then 2 subviews loaded from xib files.

    Say they are called MyViewController, then MainView and SettingsView.

    In the MyViewController.m I have:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    	[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft];
    	return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }
    

    This first call also tells the statusBar to rotate as well.

    In the other two views .m files I have:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    	// Return YES for supported orientations
    	return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }
    

    Then in my Info.plist I have "UIInterfaceOrientation" with the value "UIInterfaceOrientationLandscapeLeft".

    This works well for me.

    Check you don't have something similar already in your code that maybe clashing/re-setting the orientation!

    EDIT: Make sure the second bit of code is in every viewController inc your RootViewController.m

    Ben
  • whathelllwhathelll Posts: 10Registered Users
    edited March 2009
    I have put them in all three of my viewControllers.

    do i need to link the "view" in IB back to the main View as the file's owner?
  • whathelllwhathelll Posts: 10Registered Users
    edited March 2009
    am i flipping it wrong?
    -(void)flipToWindow2{
    	Window2ViewController *aWindow2View = [[Window2ViewController alloc] initWithNibName:@"Window2View" bundle:nil];
    	[self setWindow2ViewController:aWindow2View];
    	
    	[UIView beginAnimations:nil context:NULL];
    	[UIView setAnimationDuration:2.0];
    	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES];
    	[viewController.view removeFromSuperview];
    	[self.window addSubview:[Window2ViewController view]];
    	[UIView commitAnimations];
    }
    
  • orange goldorange gold Posts: 691Registered Users
    edited March 2009
    i had this problem i just turned all my images 90 degrees in iphoto it took about 40 seconds to turn 90 images. then i dragged them all out to a folder.. they had the same names
    i used thoose turned images and kept the vertical view on the xib file but just turned my head sideways and built like that... then in simulator tested it by pressing apple+left ... or in some cases... apple + right
    <font size="7"><font face="Comic Sans MS"><font color="Orange">APPS4LIFE</font></font></font><br />
    search for me in the app store.
  • whathelllwhathelll Posts: 10Registered Users
    edited March 2009
    yeah it's kinda hard to use IB when it's rotated.... i'll rotate the image and then when i do landscape it'll flip in semi portrait mode IN landscape so it looks cut off......
  • orange goldorange gold Posts: 691Registered Users
    edited March 2009
    well i did some google research and found a guy who said he got it working... but this is all he posted

    To get this far, I am setting the "UIInterfaceOrientation" property to "UIInterfaceOrientationLandscapeRigh t" in the .plist file, and I have changed the "shouldAutorotateToInterfaceOrientat ion" methods to return TRUE for only "UIInterfaceOrientationLandscapeRigh t". Also, I added these lines:
    [application setStatusBarOrientation: UIInterfaceOrientationLandscapeRigh t animated:NO];
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRigh t];

    to the applicationDidFinishLaunching method.



    i dont know what it means cause im a noob maybe u can make some scence of it
    <font size="7"><font face="Comic Sans MS"><font color="Orange">APPS4LIFE</font></font></font><br />
    search for me in the app store.
  • whathelllwhathelll Posts: 10Registered Users
    edited March 2009
    i might be super retarded. on the "MainWindow.xib" do i need to link the two secondary views in the connnections tab to the app delegate or to the secondary views?
  • BenODwyerBenODwyer Posts: 115Registered Users
    edited March 2009
    I built a test app to see where it was failing.

    I used a flipView app as a start.

    I found that if it was for SDK 2.0 it didn't work.

    But for SDK 2.1 and up it did.

    What SDK version are you using?
  • whathelllwhathelll Posts: 10Registered Users
    edited March 2009
    BenODwyer wrote: »
    I built a test app to see where it was failing.

    I used a flipView app as a start.

    I found that if it was for SDK 2.0 it didn't work.

    But for SDK 2.1 and up it did.

    What SDK version are you using?

    I am using 2.2
  • BenODwyerBenODwyer Posts: 115Registered Users
    edited March 2009
    Oh... that pissed on my bonfire!

    I am not sure what is going wrong for you here...

    Anyone else have any ideas?
  • whathelllwhathelll Posts: 10Registered Users
    edited March 2009
    I don't understand why it's working for the mainview and not for the secondary view called by the first view
  • KnertifiedKnertified Posts: 132Registered Users
    edited March 2009
    I'm dealing with the exact same problem. I've setup the extra view controllers correctly with TRUE, did the info.plist, rotated all the views in IB and still have this problem. I'll let you guys know if I figure it out.
    <a href="itms://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=317414065&mt=8&s=143441" target="_blank">PegLight</a> - Create peg style art on your iPhone. <img src="http://www.iphonedevsdk.com/forum/images/smilies/biggrin.gif" border=
  • KnertifiedKnertified Posts: 132Registered Users
    edited March 2009
    Okay here is a work around. I call it a work around because I really think this problem is a bug and should be fixed by apple. This workaround from another thread so I cant take the credit.

    Foreach view controller, do the following:


    Add this to the top of your code file:
    #define degreesToRadians(x) (M_PI * x / 180.0)
    
    - (void)viewWillAppear:(BOOL)animated {
    
    	// First rotate the screen:
    	[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
    	// Then rotate the view and re-align it:
    	CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation( degreesToRadians(90) );
    	landscapeTransform = CGAffineTransformTranslate( landscapeTransform, +90.0, +90.0 );
    	[self.view setTransform:landscapeTransform];
    
    }
    
    <a href="itms://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=317414065&mt=8&s=143441" target="_blank">PegLight</a> - Create peg style art on your iPhone. <img src="http://www.iphonedevsdk.com/forum/images/smilies/biggrin.gif" border=
  • essetesseessetesse Posts: 2New Users
    edited June 2009
    Thanks for all the help with this everyone. I found Knertfield's solution great except that I had problems with buttons. I couldn't click any buttons on the part of the screen close to the Home button - any touch with x-coordinate > 320 was ignored.

    If you make your view have a background, you can see what's going on. Go into Interface Builder, click on your view and in View Attributes, set it to have a background color. You'll notice that the view background is *also* rotated when we set the transform in viewWillAppear. So the background only covers part of the screen. Any buttons that are not on the background do not react when you test the app.

    To fix this, add the following line of code in viewWillAppear, before you set the status bar orientation.
    self.view.frame = CGRectMake(0.0, 0.0, 480.0, 320.0);
    
  • davidgutnik@me.comdavidgutnik@me.com Posts: 1New Users
    edited December 2009
    After 3 hours, I Hate the SDK not user friendly, i found the answer.
    It was in it all along. Find this code in your existing files, it is commented out by default.
    Basically uncomment it, and replace "Portrate" with "Landscapeleft" and there you have it.
    Cheers.

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }
  • FatFattoFatFatto Posts: 17Registered Users
    edited March 2010
    essetesse is utterly correct -- this is the answer to the 64 billion dollar bonus question.

    Getting landscape to work is a catastrophe, as of March 2010 (pad era). There are multiple problems.

    You see posts about affine transforms but that doesn't apply any more. You see posts about the undocumented routine but that doesn't apply anymore.

    You need to use the new property in plist to set the initial orientation,

    and you need to use shouldAutorotateToInterfaceOrientation properly everywhere,

    and you need to just turn the views (all of them) sideways in IB (use the little arrow at the top right of a 'view' contruction window)

    However if you are trying to swap between one view and another (landscape all the time) you face the horror of the "only works first time" problem and you have to set up a master UIViewController, that does nothing except hold all the others.

    Finally you have the horrific problem that essetesse has given the solution too, you will see the frames are all messed up.

    (Buttons near the right of your landscape screen mysteriously won't work at all...nothing works.)

    Just as essetesse says set different bg colors on all your views involved in the mighty view pyramid to see the horrors you are facing.

    This indeed is the secret solution ..
    self.view.frame = CGRectMake(0.0, 0.0, 480.0, 320.0);

    Personally I disagree about putting it in ViewWillAppear,

    I think you should put it in ViewDidLoad, and/or in shouldAutorotateToInterfaceOrientation:,

    alternately set up a timer and have it fire off 100 times a second for every view you have :-O

    Frustrating stuff !
  • MiniRobinhoMiniRobinho Posts: 160Registered Users
    edited March 2010
    I don't understand what is going on? Why can't use just click the arrow in the top right corner of interface builder?
  • FatFattoFatFatto Posts: 17Registered Users
    edited April 2010
    I don't understand what is going on? Why can't use just click the arrow in the top right corner of interface builder?

    I explained it at length in the previous post.

    The previous post is the total, exact, answer and indeed is the only way to absolutely correctly do an "all landscape, all the time" app!!!!

    The "secret" being the line where you set the frame, where you "force it" or "remind it" about the frame orientation, if you want to look at it that way.
    self.view.frame = ...



    (By the way. Don't forget that, if you are swapping in and out more than one UIView.... You just CANNOT do that unless you have a "wrapper" UIView at the top. So, create a new app with a UIView (or controller) called "holdEverythingInHere". Then if you want two, three or whatever different UIViews, create those. Set the main window's view to be holdEverythingInHere, and forget about it. From then on, set the view of holdEverythingInHere to be whatever one of your views you want at the time. You cannot just change the view of the main window. Have a "holder" view first that just sits there and remains the view of the main window. Then attach your various views to that holder view. AND DONT FORGET, all the way down you have to always apply the "secret trick" above, in holdEverythingInHere and all the "actual" views you are constructing. This is the one and only way to make it work.)
  • ageniceagenice Posts: 1New Users
    edited April 2010
    the best way to do it is:
    set the info.plist as decribed in the many posts above.
    and add the following method.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if ((interfaceOrientation==UIInterfaceOrientationPortrait)||(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown))
    {
    return NO;
    }
    if ((interfaceOrientation==UIInterfaceOrientationLandscapeLeft)||(interfaceOrientation==UIInterfaceOrientationLandscapeRight))
    {
    return YES;
    }
    }

    what this does is return a "NO" to the call any time the ipad/iphone goes into portrait and a "YES" any time it goes into landscape.
  • AndoriyuAndoriyu Posts: 4New Users
    edited April 2010
    I still have problem with it. it works only on first view and it works on another view after i'll rotate simulator.
Sign In or Register to comment.