How to show the iAD? - ios

I have used following code to display the iAD
bannerView = [[ADBannerView alloc]initWithFrame:
CGRectMake(0, 0, 320, 50)];
// Optional to set background color to clear color
bannerView.delegate=self;
[bannerView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview: bannerView];}
iAd not displayed in simulator.Every time to call following delegate method
-(void)bannerView:(ADBannerView *)bannerdidFailToReceiveAdWithError:(NSError *)error{
NSLog(#"Error loading %#",error);}

Hi You can follow the following steps for iAd
Add Delegate OF banner view
<ADBannerViewDelegate>
//Set Property
#property(nonatomic, strong) ADBannerView *bannerView;
viewDidLoad
//*************** ADBannerView ***********
bannerView = [[ADBannerView alloc]
init];
bannerView.delegate = self;
[bannerView setBackgroundColor:[UIColor clearColor]];
//***********************************************
//*********************** For iAd ***************************
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
bannerView.frame = CGRectMake(0, self.view.frame.size.height-66, 750, 80);
}
else
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending){
bannerView.frame = CGRectMake(0, self.view.frame.size.height-110, 320, 50);
}else{
bannerView.frame = CGRectMake(0, self.view.frame.size.height-50, 320, 50);
}
}else{
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending){
bannerView.frame = CGRectMake(0, self.view.frame.size.height-50, 320, 50);
}else{
bannerView.frame = CGRectMake(0, self.view.frame.size.height-50, 320, 50);
}
}
}
[self.view addSubview:bannerView];
[self.view bringSubviewToFront:bannerView];
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{
return YES;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
if ([[UIScreen mainScreen] bounds].size.height == 568) {}else{}
}
-(void)bannerView:(ADBannerView *)banner
didFailToReceiveAdWithError:(NSError *)error
{
}
Thanks

Related

How to remove ADBannerView out from UIViewController in my iOS app?

In my app, I had added the ADBannerView into the UIViewController by code
in .h file
#property (strong, nonatomic) ADBannerView *adBannerView;
in .m file
- (void)viewDidLoad
{
[super viewDidLoad];
self.adBannerView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 518, 320, 50);];
[self.view addSubview:self.adBannerView];
}
#pragma mark - ADBannerViewDelegate
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(#"bannerview did not receive any banner due to %#", error);
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
NSLog(#"bannerview was selected");
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
NSLog(#"banner action should begin");
return YES;
}
- (void)bannerViewWillLoadAd:(ADBannerView *)banner {
NSLog(#"banner will loaded");
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(#"banner was loaded");
}
My app is normally, it can show the ADBannerView. But now, I want to remove the ADBannerView out of the UIViewController, then I removed all the lines of code about the ADBannerView. I can build my app, but it cannot run, the error msg is:
Could not instantiate class named ADBannerView
Please help me to remove the ADBannerView. Thank you.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!bannerIsVisible){
//LOG_TYPE(#"AD show");
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
// banner.frame = CGRectOffset(banner.frame, 0, -50);
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if (IS_IPHONE_5) {
//LOG_TYPE(#"view height: %f",self.view.bounds.size.height);
self.adView.frame = CGRectMake(0,568-49-50, self.view.frame.size.width, 50);
}
else{
//LOG_TYPE(#"view height: %f",self.view.bounds.size.height);
self.adView.frame = CGRectMake(0,480-49-50, self.view.frame.size.width, 50);
}
}
else{
self.adView.frame = CGRectMake(0,1024-56-50, self.view.frame.size.width, 50);
}
[UIView commitAnimations];
bannerIsVisible = YES;
[self performSelector:#selector(hideAD) withObject:nil afterDelay:6];
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (bannerIsVisible){
//LOG_TYPE(#"AD error");
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
// banner.frame = CGRectOffset(banner.frame, 0, 50);
bannerIsVisible = NO;
[self performSelector:#selector(hideAD) withObject:nil afterDelay:0];
// [self performSelector:#selector(hideAD) withObject:nil afterDelay:5];
}
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{
//LOG_TYPE(#"Banner view is beginning an ad action");
BOOL shouldExecuteAction = YES;
if (!willLeave && shouldExecuteAction){
// stop all interactive processes in the app
// [video pause];
// [audio pause];
}
return shouldExecuteAction;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner{
// resume everything you've stopped
// [video resume];
// [audio resume];
}
- (void)hideAD{
//LOG_TYPE(#"Hide AD");
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if (IS_IPHONE_5) {
//LOG_TYPE(#"view height: %f",self.view.bounds.size.height);
self.adView.frame = CGRectMake(0,568-49+50, self.view.frame.size.width, 50);
}
else{
//LOG_TYPE(#"view height: %f",self.view.bounds.size.height);
self.adView.frame = CGRectMake(0,480-49+50, self.view.frame.size.width, 50);
}
}
else{
self.adView.frame = CGRectMake(0,1024-56+50, self.view.frame.size.width, 50);
}
[UIView commitAnimations];
bannerIsVisible = NO;
[self performSelector:#selector(bannerViewDidLoadAd:) withObject:self.adView afterDelay:60];
}
-(void)viewDidLoad{
...
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if (IS_IPHONE_5) {
self.adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0,568-49-50, self.view.frame.size.width, 50)];
}
else{
self.adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0,480-49-50, self.view.frame.size.width, 50)];
}
}
else{
self.adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0,1024-56-50, self.view.frame.size.width, 50)];
}
[self.view addSubview:self.adView];
self.adView.delegate=self;
bannerIsVisible=NO;
self.adView.backgroundColor = [UIColor clearColor];
....
}
if you add ADBannerView in storyboard then remove the IBoutlet of ADBannerView and its delegate.
break connection of below figure for ADBannerView
remove ADBannerViewfrom storyboard and your above code is perfect.
Your error as below.
[self.adView removeFromSuperView];

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

Handle all rotations for dynamic view in iOS

I've created a runtime image view and added subviews to it (just like splash screen concept). Now i've to handle all 4 rotations for my iPad but what is the approach for it?
My code snippet:
UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];
UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
windowBlocker.tag = 999;
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(165, 200, 450, 480)];
imageView.layer.backgroundColor=[[UIColor colorWithRed:248/255 green:248/255 blue:248/255 alpha:0.5] CGColor];
imageView.alpha = 0.6;
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;
[windowBlocker addSubview:imageView];
This below approach would be painful to set each subview's co-ordinate for each rotation. isn't it?
How to handle the rotation here. I have to disable auto layout also for scrolling purpose.
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(#"Landscape left");
self.lblInfo.text = #"Landscape left";
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(#"Landscape right");
self.lblInfo.text = #"Landscape right";
} else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
NSLog(#"Portrait");
self.lblInfo.text = #"Portrait";
} else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(#"Upside down");
self.lblInfo.text = #"Upside down";
}
}
pls guide.
Thanks
UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];
UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
windowBlocker.tag = 999;
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(165, 200, 450, 480)];
imageView.layer.backgroundColor=[[UIColor colorWithRed:248/255 green:248/255 blue:248/255 alpha:0.5] CGColor];
imageView.alpha = 0.6;
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;
[windowBlocker addSubview:imageView];
[[[mainScreen subviews] objectAtIndex:0] addSubview:windowBlocker];

Popover with picker views not showing correctly

This is the code I have for when I try to open a popover that has 2 pickerviews in it.
-(void) showPopover {
NSLog(#"Showing popover.");
BOOL right = NO;
BOOL detected = NO;
int translate = 0;
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
NSLog(#"Device is now in Portrait Mode");
translate += 600;
detected = YES;
}
else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) {
NSLog(#"Device is now in LandscapeLeft Mode ");
detected = YES;
}
else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
NSLog(#"Device is now in LandscapeRight Mode");
right = YES;
detected = YES;
}
else if([[UIDevice currentDevice]orientation] == UIDeviceOrientationPortraitUpsideDown) {
NSLog(#"Device is now in PortraitUpsideDown Mode");
detected = YES;
}
if(detected == NO) {
translate = 0;
NSLog(#"FREAK ACCIDENT, MATRIX GLITCH");
//right = YES;
}
if(right) translate += 600;
NSLog(#"Translate is %i", translate);
UIView *windowView = [[UIApplication sharedApplication] keyWindow];
UIViewController* popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 600, 350)];
popoverView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.0];
[pickerView setFrame:CGRectMake(0, 0, 150, 216)];
[popoverView addSubview:pickerView];
[secondPickerView setFrame:CGRectMake(150, 0, 450, 216)];
[popoverView addSubview:secondPickerView];
popoverContent.view = popoverView;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(200, 250, 200, 50)];
[button setTitle:#"Go!" forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[popoverView addSubview:button];
popoverContent.contentSizeForViewInPopover =
CGSizeMake(600, 300);
popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:CGRectMake(70 + translate, 512, 1, 1)
inView:windowView
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
}
And if my iPad is laying down, the "matrix glitch" error prints out and causes my popover to not function properly. It also sometimes happen if the device is in a portrait mode.
The top picture is what it looks like when my popover doesn't function properly, the bottom is it working correctly.
[[UIDevice currentDevice] orientation] gives you the physical orientation
of the device, and there are 7 possible values:
typedef enum {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait,
UIDeviceOrientationPortraitUpsideDown,
UIDeviceOrientationLandscapeLeft,
UIDeviceOrientationLandscapeRight,
UIDeviceOrientationFaceUp,
UIDeviceOrientationFaceDown
} UIDeviceOrientation;
What you probably want is the current orientation of the interface, which you get
by calling the interfaceOrientation method of the current view controller.
It has the 4 possible values
typedef enum : NSInteger {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
} UIInterfaceOrientation;

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