I'm working with an MPMoviePlayerController which renders its UIView to the right dimensions on landscape, but when rotating to portrait it is simply not resizing. I think it's parent UIView is the one not resizing. How can I set this up?
I followed the instructions that #Alex Reynolds mentions in UIView autoresizingmask not working for me. This showed me that the view does resize when rotated. I still have the problem that when the UIView for the UIViewController that holds the player is loaded, if the orientation of the device is landscape, they it renders to the right frame, but if the devise is on portrait by the time it is loaded it is not resized to it. With #Alex Reynolds' answer, all I have to do is rotate the device once and it will start resizing properly after that.
It is still bad that it won't resize the first time. Has this happened to anyone before? If so, any input is greatly appreciated.
Have you set the MPMoviePlayerController's view's autoresizingMask appropriately? Is its superview's autoresizesSubviews property set to YES? (and likewise, does this superview also resize when rotating? I like to set colourful background colours for my views during testing to verify that they resize correctly when autorotating.)
If it's still not working after checking those properties, you can always set the movie player's view's frame property manually. The super view's layoutSubviews method is generally the best place to do that, but if it's not a view you've manually subclassed, you can also do it in the view controller.
- (void)viewDidLoad
{
[super viewDidLoad];
[self play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(IBAction)dismiss:(id)sender
{
//[self.view removeFromSuperview];
_moviePlayer =nil;
[self dismissViewControllerAnimated:YES completion:nil];
}
// Do any additional setup after loading the view from its nib.
-(void)play
{
NSURL *url = [NSURL URLWithString:#"stringurlvideo"];
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:)
// name:MPMoviePlayerPlaybackDidFinishNotification
// object:_moviePlayer];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFull:)
// name:MPMoviePlayerDidEnterFullscreenNotification
// object:_moviePlayer];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidExit:)
// name:MPMoviePlayerDidExitFullscreenNotification
// object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
if([[UIScreen mainScreen] bounds].size.height==568)
{
[_moviePlayer.view setFrame:CGRectMake(0,200, 320, 200)];
}
else
{
[_moviePlayer.view setFrame:CGRectMake(0,150, 320, 200)];
}
[self.view addSubview:_moviePlayer.view];
//[_moviePlayer.view setCenter:self.view.center];
[_moviePlayer setFullscreen:YES animated:YES];
}
- (void) moviePlayBackDidFull:(NSNotification*)notification
{
}
-(void)moviePlayBackDidExit:(NSNotification*)notification
{
////[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
-(void)viewWillAppear:(BOOL)animated
{
/* if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait)
{
[_moviePlayer.view setFrame:CGRectMake(0,200, 320, 200)];
CGRect rect=[bar frame];
rect.size.width=self.view.frame.size.width;
[bar setFrame:rect];
}
else
{
CGRect rect=[bar frame];
rect.size.width=480;
[bar setFrame:rect];
[_moviePlayer.view setFrame:CGRectMake(0,44, 480, 320-44)];
}*/
}
- (void)moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:#selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
- (BOOL)shouldAutorotate
{
return YES;
}
/*- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}*/
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation==UIInterfaceOrientationPortrait && toInterfaceOrientation!=UIInterfaceOrientationPortraitUpsideDown )
{
if([[UIScreen mainScreen] bounds].size.height==568)
{
[_moviePlayer.view setFrame:CGRectMake(0,200, 320, 200)];
}
else
{
[_moviePlayer.view setFrame:CGRectMake(0,150, 320, 200)];
}
CGRect rect=[bar frame];
rect.size.width=self.view.frame.size.width;
[bar setFrame:rect];
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation ==UIInterfaceOrientationLandscapeRight)
{
CGRect rect=[bar frame];
if([[UIScreen mainScreen] bounds].size.height==568)
{
rect.size.width=568;
}
else{
rect.size.width=480;
}
[bar setFrame:rect];
[_moviePlayer.view setFrame:CGRectMake(0,44, rect.size.width, 320-44)];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
/* if(fromInterfaceOrientation==UIInterfaceOrientationPortrait && fromInterfaceOrientation!=UIInterfaceOrientationPortraitUpsideDown )
{
CGRect rect=[bar frame];
rect.size.width=568;
[bar setFrame:rect];
[_moviePlayer.view setFrame:CGRectMake(0,44, 480, 320-44)];
}
else
{
[_moviePlayer.view setFrame:CGRectMake(0,200, 320, 200)];
CGRect rect=[bar frame];
rect.size.width=self.view.frame.size.width;
[bar setFrame:rect];
}*/
}
- (void)didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation ==UIInterfaceOrientationLandscapeRight)
{
CGRect rect=[bar frame];
if([[UIScreen mainScreen] bounds].size.height==568)
{
rect.size.width=568;
}
else{
rect.size.width=480;
}
[bar setFrame:rect];
[_moviePlayer.view setFrame:CGRectMake(0,44, rect.size.width, 320-44)];
}
else if(orientation==UIInterfaceOrientationMaskPortrait && orientation!=UIDeviceOrientationPortraitUpsideDown)
{
if([[UIScreen mainScreen] bounds].size.height==568)
{
[_moviePlayer.view setFrame:CGRectMake(0,200, 320, 200)];
}
else
{
[_moviePlayer.view setFrame:CGRectMake(0,150, 320, 200)];
}
CGRect rect=[bar frame];
rect.size.width=self.view.frame.size.width;
[bar setFrame:rect];
}
}
Related
I have used AVPictureInPictureController in AVPPlayer and initialized it as AVPlayerLayer.
- (id)initWithFrame:(CGRect)frame contentURL:(NSURL*)contentURL
{
self = [super initWithFrame:frame];
if (self) {
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:contentURL];
self.moviePlayer = [AVPlayer playerWithPlayerItem:playerItem];
playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.moviePlayer];
if ([AVPictureInPictureController isPictureInPictureSupported])
{
self.avVPictureInPictureController = [[AVPictureInPictureController alloc] initWithPlayerLayer:playerLayer];
}
[playerLayer setFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
[self.moviePlayer seekToTime:kCMTimeZero];
[self.layer addSublayer:playerLayer];
self.contentURL = contentURL;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playerFinishedPlaying) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
[self initializePlayer:frame];
}
return self;
}
Now when I try to present FPPopoverController ( a custom class to present PopOvers on iPhone and iPad ) it doesn't show on the screen.
I use the following code to present FPPopOverController
//That's how I call
self.audioSubtitlePopoverController.presentPopoverFromPoint(point)
//Definition of presentPopoverFromPoint
-(void)presentPopoverFromPoint:(CGPoint)fromPoint
{
self.origin = fromPoint;
//NO BORDER
if(self.border == NO)
{
_viewController.title = nil;
_viewController.view.clipsToBounds = YES;
}
_contentView.relativeOrigin = [_parentView convertPoint:fromPoint toView:_contentView];
[self.view removeFromSuperview];
NSArray *windows = [UIApplication sharedApplication].windows;
if(windows.count > 0)
{
_parentView=nil;
_window = [windows objectAtIndex:0];
//keep the first subview
if(_window.subviews.count > 0)
{
_parentView = [_window.subviews lastObject];
NSLog(#"%# %#",_parentView,_viewController);
[_parentView addSubview:self.view];
[_viewController viewDidAppear:YES];
[self.view bringSubviewToFront:_parentView];
}
}
else
{
[self dismissPopoverAnimated:NO];
}
[self setupView];
self.view.alpha = 0.0;
[UIView animateWithDuration:0.2 animations:^{
self.view.alpha = self.alpha;
}];
[[NSNotificationCenter defaultCenter] postNotificationName:#"FPNewPopoverPresented" object:self];
//navigation controller bar fix
if([_viewController isKindOfClass:[UINavigationController class]])
{
UINavigationController *nc = (UINavigationController*)_viewController;
UINavigationBar *b = nc.navigationBar;
CGRect bar_frame = b.frame;
bar_frame.origin.y = 0;
b.frame = bar_frame;
}
}
Even present from view doesn't work too
self.audioSubtitlePopoverController.presentPopoverFromView(self.view)
// Definition of presentPopoverFromView
-(void)presentPopoverFromView:(UIView*)fromView
{
SAFE_ARC_RELEASE(_fromView);
_fromView = SAFE_ARC_RETAIN(fromView);
[self presentPopoverFromPoint:[self originFromView:_fromView]];
}
Can anyone please assist. Would be grateful.
FPPopover is deprecated.
You should use the native Possibility to display Popovers or WEPopover instead.
I am developing an ios application with viewcontroller which has two subviews A) mpmoviecontroller and B) pageviewcontroller. if the player is not in full screen mode and I change orientation subviews alignment is ok (I handle orientation change and make new CGRects for subviews). When I switch my video mode to full screen, rotate to landscape and zoom out, my pageviewcontrollers view is gone out of the screen. Here is my code
- (void)viewDidLoad
{
[super viewDidLoad];
self.streamPlayer.controlStyle = MPMovieControlStyleDefault;
[self.view addSubview: self.streamPlayer.view];
[self.streamPlayer prepareToPlay];
NSURL *streamURL = [NSURL URLWithString:#"http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8"];
[self.streamPlayer setContentURL:streamURL];
[self.streamPlayer play];
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
[self setFramesForPotrait];
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
- (void)orientationChanged:(NSNotification *)notification
{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
[self setFramesForPotrait];
NSLog(#"%f",[[UIScreen mainScreen] bounds].size.height);
NSLog(#"%f",[[UIScreen mainScreen] bounds].size.width);
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
[self setFramesForLandscapeMode];
// self.pageViewController.view.frame = self.pageViewContainterRect;
NSLog(#"%f",[[UIScreen mainScreen] bounds].size.height);
NSLog(#"%f",[[UIScreen mainScreen] bounds].size.width);
}
}
-(void)setFramesForPotrait
{
CGRect frame = [[UIScreen mainScreen] bounds];
_videoFrameRect = CGRectMake(0,_BAR_HEIGHT, frame.size.width,_VIDEO_HEIGHT_PORTRAIT);
_pageViewContainterRect = CGRectMake(frame.origin.x, _BAR_HEIGHT + _VIDEO_HEIGHT_PORTRAIT, frame.size.width, frame.size.height-_BAR_HEIGHT-_VIDEO_HEIGHT_PORTRAIT);
[self.pageViewController.view setFrame :self.pageViewContainterRect ];
[self.streamPlayer.view setFrame: _videoFrameRect];
}
-(void)setFramesForLandscaeMode
{
CGRect frame = [[UIScreen mainScreen] bounds];
_videoFrameRect = CGRectMake(0,_BAR_HEIGHT, frame.size.height/2,frame.size.width-_BAR_HEIGHT);
_pageViewContainterRect = CGRectMake(frame.size.height/2, _BAR_HEIGHT, frame.size.height/2,frame.size.width-_BAR_HEIGHT);
self.pageViewController.view.frame = self.pageViewContainterRect;
[self.streamPlayer.view setFrame: _videoFrameRect];
}
I have a UITableViewController that I want to add iAds to. I want the ad to display at the bottom of the screen at all times. I have followed the answer here: https://stackoverflow.com/a/9857798/2584268 and have achieved this behavior. However, the ad is hidden in the beginning and only appears when the user scrolls the table. How can I get the ad to appear at the bottom of the screen when the view loads, not just when the user scrolls?
To show the ad when the view appears, I add the banner view on viewDidAppear.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_myIAD = [[self appdelegate] myIAD];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
//iPhone code
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 50, 320, 50);
}
else
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 114, 320, 50);
}
}
else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 32, 480, 32);
}
else
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 84, 480, 32);
}
}
}
else
{
//iPad code
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 66, 768, 66);
}
else
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 130, 768, 66);
}
}
else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 66, 1024, 66);
}
else
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 130, 1024, 66);
}
}
}
[self.view addSubview:_myIAD];
}
There is a ton of code in there to deal with iOS6.1 and iPads and iPhones, but it works real well. I always like to use the statusBarOrientation to find the orientation, it works better.
As you can see there is a line
_myIAD = [[self appdelegate] myIAD];
I actually make the banner in the app delegate and use it in all the view controllers. To handle rotation, I register for a notification in viewDidLoad.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(updateUI:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
And basically use the same code in the viewDidAppear in the method updateUI:
The only other thing I did was to put in this code to keep the iAd at the bottom.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect frame = _myIAD.frame;
frame.origin.y = _myTableView.contentOffset.y + _myTableView.frame.size.height-_myIAD.frame.size.height; // Move view to the bottom on scroll
_myIAD.frame = frame;
[_myTableView bringSubviewToFront:_myIAD];
}
I am running a phonegap application on iOS7 and I need to resize the UIView when the keyboard opens and when the orientation of the device changes.
I have some of the resize working but I am stuck when the orientation of the device is LandscapeRight, the first time the keyboard opens it slides up then the second time it slides it up even more.
I have search similar answers on stackoverflow and none have solved what I am looking for. So, please don't just copy and paste a solution from else where, thanks.
MainViewController.m
int screenWidth;
int screenHeight;
float keyboard_offset = 80.0;
- (void)viewWillAppear:(BOOL)animated
{
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardWillHideNotification object:nil];
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
self.webView.backgroundColor = [UIColor blackColor];
self.webView.opaque=NO;
screenWidth = self.view.frame.size.width;
screenHeight = self.view.frame.size.height;
}
[super viewWillAppear:animated];
}
- (void)orientationChange:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationLandscapeLeft:
[self.view setFrame: CGRectMake(-keyboard_offset, 0, screenWidth + keyboard_offset, screenHeight)];
break;
case UIDeviceOrientationLandscapeRight:
[self.view setFrame: CGRectMake(keyboard_offset, 0, screenWidth + keyboard_offset, screenHeight)];
break;
case UIDeviceOrientationPortrait:
case UIDeviceOrientationPortraitUpsideDown:
[self.view setFrame: CGRectMake(0, 0, screenWidth, screenHeight)];
break;
default:
break;
};
}
- (void)keyboardDidShow:(NSNotification *) notification
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChange:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
if([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft)
{
[self.view setFrame: CGRectMake(-keyboard_offset, 0, screenWidth + keyboard_offset, screenHeight)];
}
else if([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight)
{
[self.view setFrame: CGRectMake(keyboard_offset, 0, screenWidth + keyboard_offset, screenHeight)];
}
else
{
[self.view setFrame: CGRectMake(0, 0, screenWidth, screenHeight)];
}
}
- (void)keyboardDidHide:(NSNotification *) notification
{
[self.view setFrame: CGRectMake(0, 0, screenWidth, screenHeight)];
}
AppDelegate.m
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
/*
Orientation change for iOS7
*/
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
self.window.clipsToBounds = YES;
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
/**
* Change the status bar color on orientation change.
*/
- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationLandscapeLeft:
self.window.frame = CGRectMake(-20, 0, screenWidth, screenHeight);
self.window.bounds = CGRectMake(-20, 0, screenWidth, screenHeight);
break;
case UIDeviceOrientationLandscapeRight:
self.window.frame = CGRectMake(20, 0, screenWidth, screenHeight);
self.window.bounds = CGRectMake(20, 0, screenWidth, screenHeight);
break;
case UIDeviceOrientationPortrait:
self.window.frame = CGRectMake(0, 20, screenWidth, screenHeight);
self.window.bounds = CGRectMake(0, 20, screenWidth, screenHeight);
break;
case UIDeviceOrientationPortraitUpsideDown:
self.window.frame = CGRectMake(0, -20, screenWidth, screenHeight);
self.window.bounds = CGRectMake(0, -20, screenWidth, screenHeight);
break;
default:
break;
};
}
CDVViewController.m
/*
Change the status bar color to the old style
*/
-(UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad
{
[super viewDidLoad];
/*
Only perform these actions for iOS 7 or above
*/
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
[self setNeedsStatusBarAppearanceUpdate];
}
}
I have a problem with an app that won't set frames outside -init and -viewWillLayoutSubviews methods. What should happen when one taps the editButton is an animation that will hide the editor view. Nonetheless, nothing happens as I test it. The problem doesn't come from the animation method since the -setFrame method as it - not included in the block - doesn't work neither.
Here is the code :
-(id)init {
if (self = [super init]) {
editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:#selector(editButtonTapped)];
doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(doneButtonTapped)];
editor = [[UIView alloc] init];
[editor setBackgroundColor:[UIColor yellowColor]];
editor.clipsToBounds = YES;
editorIsOpen = YES;
portraitRegularModeEditorRect = CGRectMake(15, 59, 738, 100);
portraitClosedEditorEditorRect = CGRectMake(15, 59, 738, 0);
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[[self view] addSubview:editor];
[[self view] setBackgroundColor:[UIColor blueColor]];
}
-(void)viewDidAppear:(BOOL)animated {
[self setForRegularMode];
}
-(void)viewWillLayoutSubviews {
UIInterfaceOrientation io = [[UIApplication sharedApplication] statusBarOrientation];
if (io == UIInterfaceOrientationPortrait || io == UIInterfaceOrientationPortraitUpsideDown) {
//portrait
[editor setFrame:portraitRegularModeEditorRect];
} else {
//landscape
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)editButtonTapped {
[self setForScenarioLinesEditingMode];
}
-(void)doneButtonTapped {
[self setForRegularMode];
}
-(void)setForRegularMode {
editingMode = CPRegularMode;
if (!editorIsOpen) {
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationCurveEaseOut animations:^(void){
[editor setFrame:portraitRegularModeEditorRect];
} completion:^(BOOL finished) {
editorIsOpen = YES;
}];
}
[[self navigationItem] setRightBarButtonItems:[[NSArray alloc] initWithObjects:editButton,nil]];
}
-(void)setForScenarioLinesEditingMode {
editingMode = CPScenarioLinesEditingMode;
if (editorIsOpen) {
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations:^(void){
[editor setFrame:portraitClosedEditorEditorRect];
} completion:^(BOOL finished) {
editorIsOpen = NO;
}];
}
[[self navigationItem] setRightBarButtonItems:[[NSArray alloc] initWithObjects:doneButton,nil]];
}
If anyone can help, thanks in advance ;)
I think that the problem in your case is the fact that in -(void)viewWillLayoutSubviews method you set, lets say the default frame of your view, if you try to change the frame in other methods after the setFrame is called on your view, the -(void)viewWillLayoutSubviews will also be called and the frame of the view will be the default one. Try to remove the setFrame from your -(void)viewWillLayoutSubviews.
Is your view controller set up in storyboards, and are you using Autolayout (which is on by default?) If so, setFrame won't work and you need to edit constraints after creating outlets to them from the storyboard.
Alternatively, you can turn off Autolayout in your storyboard, as shown here.