iPad resize UIView when keyboard is shown - ios

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];
}
}

Related

iAd in UITableViewController

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];
}

Status bar backgroundColor

I am using ios 7 I want to set stauts bar background image.
I have done this but still it is not changing anything:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor redColor]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}
I have done this like .h file
#property (retain, nonatomic) UIWindow *statusBarBackground;
and in .m file
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
self.statusBarBackground = [[UIWindow alloc] initWithFrame: CGRectMake(0, 0, self.window.frame.size.width, 20)];
self.statusBarBackground.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:#"statusbar_bg"]];
[self.statusBarBackground makeKeyAndVisible];
}
add this to your controllers
- (void) viewDidLayoutSubviews {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0")) {
CGRect viewBounds = self.view.bounds;
if (viewBounds.origin.y == 0) {
CGFloat topBarOffset = self.topLayoutGuide.length;
viewBounds.origin.y -= topBarOffset;
self.view.bounds = viewBounds;
}
}
}
your code works, but you have to modify it a bit. here is what it should look like..
// Override point for customization after application launch.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
//change this to match your navigation bar or view color or tool bar
//You can also use addStatusBar.backgroundColor = [UIColor BlueColor]; or any other color
addStatusBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg1.png"]];
//here you are adding the image as the background image
[self.window.rootViewController.view addSubview:addStatusBar];
don't forget to import your image to the project. now i have just plugged in the above code in application didfinishwithoptions of the app delegate, but you should be able to use the same if you want different views using the same.
You have to do 2 things.
(1) Open your info.plist and set "View controller-based status bar appearance" = NO
(2) add these lines to application:didFinishLaunchingWithOptions
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
self.window.clipsToBounds = YES;
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
self.window.frame = CGRectMake(20, 0,self.window.frame.size.width-20,self.window.frame.size.height);
self.window.bounds = CGRectMake(20, 0, self.window.frame.size.width, self.window.frame.size.height);
} else
{
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
}
}

Can't redraw the popover in correct place after changing the orientation of the device

I have a tabbar app in which I need to show a popover from the tabBarItem by clicking on it. So, I in my appDelegate:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (viewController == [self.objTabBarController.viewControllers objectAtIndex:2])
{
if (self.settingsPopover == nil) {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main - iPad" bundle: nil];
SettingsViewController *settingsController = [mainStoryboard instantiateViewControllerWithIdentifier: #"SettingsPopover"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:settingsController];
self.settingsPopover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
self.settingsPopover.delegate = self;
CGSize screenSize;
if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortraitUpsideDown){
screenSize = CGSizeMake ([UIScreen mainScreen].applicationFrame.size.width, [UIScreen mainScreen].applicationFrame.size.height);
} else {
screenSize = CGSizeMake ([UIScreen mainScreen].applicationFrame.size.height, [UIScreen mainScreen].applicationFrame.size.width);
}
NSLog(#"WIDTH = %f, HEIGHT = %f", screenSize.width, screenSize.height);
screenSize.height -= 50;
screenSize.width = screenSize.width / 2 + 105;
CGRect rect = CGRectMake(screenSize.width, screenSize.height, 1, 1);
[self.settingsPopover presentPopoverFromRect:rect inView:self.window.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
} else {
[self.settingsPopover dismissPopoverAnimated:NO];
self.settingsPopover = nil;
}
return NO;
}
}
return YES;
}
So it displays correctly. But I need to redraw the popover after the change of the device orientation. For this purposes I made:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(handleDidChangeStatusBarOrientationNotification:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
}
- (void) handleDidChangeStatusBarOrientationNotification:(NSNotification *)notification;
{
if (self.settingsPopover)
{
CGSize screenSize;
if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortraitUpsideDown){
screenSize = CGSizeMake ([UIScreen mainScreen].applicationFrame.size.width, [UIScreen mainScreen].applicationFrame.size.height);
} else{
screenSize = CGSizeMake ([UIScreen mainScreen].applicationFrame.size.height, [UIScreen mainScreen].applicationFrame.size.width);
}
NSLog(#"WIDTH = %f, HEIGHT = %f", screenSize.width, screenSize.height);
screenSize.height -= 50;
screenSize.width = screenSize.width / 2 + 105;
CGRect rect = CGRectMake(screenSize.width, screenSize.height, 1, 1);
[self.settingsPopover presentPopoverFromRect:rect inView:self.window.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
So, the NSLog shows the correct screenSize after the changing the orientation but the popover shows in incorrect place. Can anyone help me to solve this?
For that you have to close your Popover first and then show it again as I have done to solve my problem
In case anyone is looking for an answer in Swift 3...
1) Register for orientation change events.
NotificationCenter.default.addObserver(self, selector: #selector(screenRotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
2) Inside your view controller being presented as a popover...
func screenRotated() {
// Redraw the popover.
DispatchQueue.main.async {
self.preferredContentSize = CGSize(width: UIScreen.main.bounds.width, height: self.view.frame.height)
}
}

rotation of video hide videocontroller

when i rotate a video from portrait to landscape then it opens in landscpae mode perfectly but hide video controller bar. code which i am using :
-(void) readyPlayer
{
mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"abc" ofType:#"mp4"]]];
[[NSNotificationCenter defaultCenter] removeObserver:mp
name:MPMoviePlayerPlaybackDidFinishNotification
object:mp.moviePlayer];
// Register this class as an observer instead
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mp.moviePlayer];
// Set the modal transition style of your choice
mp.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
mp.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
for(UIView* subV in mp.moviePlayer.view.subviews) {
subV.backgroundColor = [UIColor clearColor];
}
mp.moviePlayer.fullscreen=YES;
[self.view addSubview:mp.view];
[mp.moviePlayer play];
}
- (void)deviceOrientationDidChange:(NSNotification *)notification {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
rotation = 0;
// Later we may handle the Orientation of Faceup to show a Map. For now let's ignore it.
if (orientation == UIDeviceOrientationPortrait) {
{
NSLog(#"portrait");
[mp.view setFrame:CGRectMake(0,0,screenWidth,screenHeight)];
rotation = 0;
mp.view.transform = CGAffineTransformMakeRotation(rotation);
}
}
else if (orientation != UIDeviceOrientationUnknown) {
//CGRect bounds = [[UIScreen mainScreen] bounds];
switch (orientation) {
case UIDeviceOrientationLandscapeLeft:
{
NSLog(#"Case 1");
[mp.view setFrame:CGRectMake(0,0,screenWidth,screenHeight)];
rotation = M_PI_2;
mp.view.transform = CGAffineTransformMakeRotation(rotation);
}
break;
case UIDeviceOrientationLandscapeRight:
{
NSLog(#"Case 2");
rotation = -M_PI_2;
[mp.view setFrame:CGRectMake(0,0,screenWidth,screenHeight)];
mp.view.transform = CGAffineTransformMakeRotation(rotation);
}
break;
case UIDeviceOrientationPortraitUpsideDown:
{
NSLog(#"Case 3");
rotation = -M_PI;
[mp.view setFrame:CGRectMake(0,0,screenWidth,screenHeight)];
mp.view.transform = CGAffineTransformMakeRotation(rotation);
}
break;
default:
break;
}
}
}
Please help.
If your application needs to support only portrait orientation and all the videos need to play in both orientations, do the steps.
1->Project file->Summary->SupportedOrientations -> tick yes for all orientation values.
2->In your root view Controller implement (BOOL)shouldAutorotate and return NO.

MPMoviePlayerController view not resizing

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];
}
}

Resources