iAd frame doesn't rotate to landscape using setAutoresizingMask on iOS8 - ios

I have created an iAd frame right on top of the tab bar and I am using setAutoresizingMask to keep it in the right place when rotating the screen. Here is my code in viewDidLoad:
iAd = [[ADBannerView alloc] init];
bannerIsVisible=NO;
iAd.delegate=self;
[iAd setAutoresizingMask: UIViewAutoresizingFlexibleTopMargin
| UIViewAutoresizingFlexibleWidth];
// set iAd frame
iAd.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 50);
[self.view addSubview:iAd];
This will create the banner just below the screen, so it will appear when the ad is loaded using the bannerViewDidLoadAd: delegate method and going back using the didFailToReceiveAdWithError method.
This works perfectly on iOS 6 and iOS7.
On iOS8 the banner appears in the right place when portrait, but when I rotate the screen to landscape, the banner appears around 10 points over the right place. Is like it doesn't take into consideration that the height of the frame is smaller when landscape.
Did something change in iOS8 about setAutoresizingMask?
Thanks

Related

UIWebView display and touch area on device rotation

I have a webview which fills the full screen of the app. The content gets loaded from a web url, and is displayed correctly.
The problem is when I load it in portrait mode and then rotate to landscape, the right side can not receive any touch events. For example, the portrait screen width is 320, when I rotate to landscape which is 480, the right area (width 480-320=160) does not respond to touch.
The content is always displayed correctly, it fills the whole width, just the touch events don't work.
If I load it in landscape and then rotate to portrait, it works correctly.
A similar problem was reported on Apple's developer forum here
You should basically add
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
}
to the UIWebView's viewcontroller

UIViewController view not size correctly when running iOS7 simulator

I have a custom UIViewController which create a view containing an action bar at the top (view with 4 buttons), a tableview and then another view below the tableview. Layout is done all in code and is not using auto layout.
Everything works perfectly on various device with iOS 7.0 and 7.0.2, but in the simulator, the root view of the controller get anchored at the top right corner of the screen (0,0) instead of below the navigation bar.
I'm going to force the relay out in the viewDidAppear: method, but this seem like a hack...
Thanks for any insights
Edit: added an image. You can see the UIView highlighted. As ManicMonkOnMac mentioned, the UIView is under the toolbar (but this only happens in the simulator, on the device, the view lines up fine)
In the loadView method on the controller, i set the frame when creating the view:
- (void)loadView
{
// Our parent view controller will resize us appropriately. The size set
// here is a convenience for initial view layout.
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
But this frame is later changed. Not by my code, though, but by UIkit code)
Edit2: addded loadView method body
EDIT: After going through session 201 of WWDC 2013, I think I have the solution.
in iOS 7 there is a property that you can set on your view controllers to specify whether you want the views to be overlapped by navigation bar.
viewController.edgesForExtendedLayout = UIRectEdgeNone;//UIRectEdgeAll specifies that nav bars should overlap the view.
Unlike iOS 6, navigation bars are placed over the views in iOS 7.
Use the frame size that excludes the navigation bar.
code:
CGRect frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y+self.navigationController.navigationBar.frame.size.height,self.view.frame.size.width,self.view.frame.size.height);
CustomView *view = [[CustomView alloc] initWithFrame:frame];
[self.view addSubview: view];

position of UIScrollView getting changed when Orientation is changing in ipad twice

The scrollview is changing its position automatically when I switch to landscape and portrait modes more than one time while scrolling the scrollview.
What else I have to do...to retain its position in the same manner as it was loaded for the first time. I would like to scroll horizontally all the time in landscape mode and always vertical in portrait mode.
The below code is just I'm using:
UIScrollView * myBookScrollView = [[MyBooksScrollView alloc] init];
myBookScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
myBookScrollView.clipsToBounds = YES;
myBookScrollView.scrollEnabled = YES;
[self.view addSubview:myBookScrollView];
Did you try to set it's autoresizingMask? Setting it to UIViewAutoresizingFlexibleWidth might help.

Subview is not oriented properly

I have created a subview which is used as a HUD in an iOS app. The app supports portrait and landscape display orientations.
The subview appears in portrait mode sometimes even if the mode is landscape. The subview is added by these lines:
self.infoHUDViewController = [[[InfoHUDViewController alloc] initWithNibName:#"InfoHUD" bundle:nil] autorelease];
[self.view addSubview:self.infoHUDViewController.view];
So it works very well if the subview is added in the viewDidLoad method. However, it does not work in landscape mode if the view is added in an IBAction method which responds to a button press. The subview appears as if in portrait mode (it appears 90° rotated, fills only the half screen width, and extends beyond the screen bounds).
What is really odd: In the init method of the subview's view controller the display orientation is correctly set to landscape. Am I missing something here?
I found a fix for this problem.
I added
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
self.view.frame = CGRectMake(0.0f, 0.0f, 480.0f, 320.0f);
} else {
self.view.frame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
}
to the viewDidLoad method. Now everything works as excepted in all situations.

iPad autoresizingMask creating bottom margin

LiveStreamTable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 768, 960)];
LiveStreamTable.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:LiveStreamTable];
This code is in viewDidLoad. In between viewDidLoad and viewWillAppear the table is resized to 916 height leaving 44 empty px at the bottom (this is in portrait mode). I know it's in between from printing debug info.
The view has a status bar and a nav bar at the top, so 960 should fill up the whole screen just right. And it does with the autoresizingMask line commented out. I only want autoresizingMask to affect it when the iPad is rotated so that landscape mode works.
I'm also having a problem where if I go to the screen in landscape in the first place then it gets sized wrong. It ends up a little too wide and too short. I assume that's related.
How do I use autoresizingMask correctly so that my table will take up the whole view (except status and nav bars) in both portrait and landscape?
Your autoresizing mask is correct, but the way you init the frame is not.
Consider if this view is opened in landscape, frame (0, 0, 768, 960) yield the wrong frame.
instead of
LiveStreamTable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 768, 960)];
you should try
LiveStreamTable=[[UITableView alloc]initWithFrame:self.view.bounds];
This will initialize the frame according to your current ViewController's view.
I hope this help.

Resources