I have UIViewController which contains UICollectionView. On clicking on any of the UICollectionViewCell I show the detailed contents of the cell in a modal view. I have added objects (UILabel, UIImage etc.) in modal view through storyboard. I resize frames when device orientation is changed using NSNotificationCenter:
In viewDidLoad method of modal controller:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
NSNotificationCenter* notifCenter = [NSNotificationCenter defaultCenter];
[notifCenter addObserver:self selector:@selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil];
orientationChanged content:
-(void) orientationChanged {
if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
self.productImage.frame = CGRectMake(61, 5, 124, 138);
self.siteLogo.frame = CGRectMake(61, 146, 124, 90);
self.productName.frame = CGRectMake(220, 5, 150, 102);
self.productPrice.frame = CGRectMake(220, 120, 124, 21);
}
else {
self.productImage.frame = CGRectMake(61, 5, 124, 138);
self.siteLogo.frame = CGRectMake(61, 146, 124, 90);
self.productName.frame = CGRectMake(20, 244, 207, 102);
self.productPrice.frame = CGRectMake(61, 354, 124, 21);
}
}
Now when I start my app in portrait mode and click of any of the UICollectionViewCell the modal view shows up correctly, also now when I change to landscape mode (without dismissing modal view) I am able to resize frames due to above method.
Problem is when I start my app in landscape mode and then I click on UICollectionViewCell the modal view shows up in portrait mode. I want it to be in landscape mode with correctly resizing frames. I tried setting frames in viewDidLayoutSubviews & in viewDidAppear but of no use.
content of viewDidLayoutSubviews:
-(void)viewDidLayoutSubviews{
self.productImage.autoresizingMask = 0;
self.productPrice.autoresizingMask = 0;
self.productName.autoresizingMask = 0;
self.siteLogo.autoresizingMask = 0;
if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
self.productImage.frame = CGRectMake(61, 5, 124, 138);
self.siteLogo.frame = CGRectMake(61, 146, 124, 90);
self.productName.frame = CGRectMake(220, 5, 150, 102);
self.productPrice.frame = CGRectMake(220, 120, 124, 21);
}
else {
self.productImage.frame = CGRectMake(61, 5, 124, 138);
self.siteLogo.frame = CGRectMake(61, 146, 124, 90);
self.productName.frame = CGRectMake(20, 244, 207, 102);
self.productPrice.frame = CGRectMake(61, 354, 124, 21);
}
}
Thanks in Advance.