Note that there are some explanatory texts on larger screens.

plurals
  1. POUIInterfaceOrientation remains in portrait
    text
    copied!<p>I've got a header/brand image which <em>changes between iPad and iPhone</em>, but <em>will not change the picture when changing from portrait to landscape</em>, which is really important that it does.</p> <p>I have this HeaderView Class, which is called by tableViewControllers like this:</p> <pre><code>self.tableView.tableHeaderView = [[HeaderView alloc] initWithText:@""]; </code></pre> <p>which holds a UIImageView:</p> <pre><code>@interface HeaderView : UIImageView{ } - (id)initWithText:(NSString*)text; - (void)setText:(NSString*)text; @end </code></pre> <p>For the M file, we find where I'm not getting the result I want:</p> <pre><code>#import "HeaderView.h" #define IDIOM UI_USER_INTERFACE_IDIOM() #define IPAD UIUserInterfaceIdiomPad @interface HeaderView() { UILabel*label; } @end @implementation HeaderView - (id)initWithText:(NSString*)text { UIImage* img = [UIImage imageNamed:@"WashU.png"]; UIImage* iPhonePortrait = [UIImage imageNamed:@"WashU2.png"]; UIImage* image = [[UIImage alloc] init]; UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; //different header image for different devices... if(IDIOM==IPAD){ image = img; } else{ if(UIInterfaceOrientationIsPortrait(interfaceOrientation)){ image = iPhonePortrait; } else if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) { iPhonePortrait = nil; image = img; } } [headerImageView setImage:image]; if (self = [super initWithImage:image]){ } return self; } </code></pre> <p>I also have added these methods:</p> <pre><code>-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } -(BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } </code></pre> <p>I'm sure its a classic sort of question, but I'm reasonably stumped. Also, if I remove </p> <pre><code>[headerImageView setImage:image]; </code></pre> <p>, and </p> <pre><code>[self addSubview:headerImageView]; </code></pre> <p>, the image still shows up, which means that </p> <pre><code>if (self = [super initWithImage:image]) </code></pre> <p>is doing all the display work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload