iphone: rotation in mpmovieplayercontroller? - iphone

I have a small view on top of an mpmovieplayercontroller. When it is not fullscreen, I am able to adjust the frame of the view to the orientation (when the device rotates). But when I enter fullscreen mode, alothough I manage to present the view, I'm no longer able to maintain the correct frame when the device rotates. It looks like in fullscreen mode, the system simply using CGAffineTransformRotate on the status bar and the moviePlayer. How can I apply this CGAffineTransformRotate to rotate my view correctly?
EDIT:
Ok, so I updated the code to rotate 90% in the X axis after a change in orientation of the mpmovieplayercontroller but the view simply disappears after the first rotate. Here is my code:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
float angle = M_PI / 2; //rotate 180°, or 1 π radians
theView.layer.transform = CATransform3DMakeRotation(angle, 1.0, 0.0, 0.0);
[self changePositionBasedOnOrientation:toInterfaceOrientation]; //here we change the frame of the view
}

I'm not sure if this would necessarily be the correct way to do it (I guess you're adding a subview to the MPMoviePlayerController view?), but what you seem to be after is a callback to when the movie player rotates in fullscreen so you can adjust your own custom views.
You could register for rotation notifications on your custom view, which can then adjust itself every time it receives a callback. You register for rotation notifications as follows:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(layoutViewForOrientation:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
You should remember to endGeneratingDeviceOrientationNotifications and remove your notification observer when you're done with the fullscreen mode.

Ok,
So the best way to overlay the mpmovieplayercontroller in fullscreen is to it like that:
[[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] addSubview:mySubview]
It's a bit hacky, but legitimate. It gives you an easy way to deal with rotations (instead of using transformations).

Related

Control done button

I have a view with some objects, one of them is a webview where I play a video, this view change the size and the position of the object when the device rotates. The problem occurs when I am playing the video in full screen, if I start watching the video in landscape and while I am watching the video (full screen) I rotate the device and then I hit the done button when I return to the view the objects are not in the position that they should be in that orientation.
I set the position in a function, I call that function in viewdidload and also in willAnimateRotationToInterfaceOrientation but how can I control the rotation while I am watching the video?
You could do something like this:
-(void) viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playerPlaybackDidFinish:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
}
- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
[self resizeSubviews];
}
So, when the playback finishes, you call your method to resize your subviews, and by the time the player closes, your view should look correct for the orientation.
You could also register for MPMoviePlayerWillExitFullscreenNotification instead, if that more properly fits your needs.

Flip Everything on Screen After a Fixed Interval has Elapsed - Cocos2d

I have a timer set up, in place, and working fully. My problem is that I do not know if it is possible to completely flip everything on screen and keep it in the same position after a certain amount of time has elapsed.
E.G.
I have a tree. After 30 seconds has passed flip the orientation from "landscapeleft" to "landscapeRight" and flip all sprites/timers on screen.
Is it possible?
Should I just change the orientation, check to see if the orientation has changed and if it has, change the sprites rotation?
Also, I would really like to Thank EVERYONE on this site for all of there help and putting up with my "easily answered" questions.
Thank You!
you could use a scheduling method like nash suggested along with a CCDirector orientation method [[CCDirector sharedDirector] setDeviceOrientation:kCCDeviceOrientationPortrait]; or whichever orientation you need.
-(void) flipOrientation:(ccTime)delta {
CCDirector *director = [CCDirector sharedDirector];
if ([director deviceOrientation] == kCCDeviceOrientationLandscapeLeft )
[director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
}
then when you schedule your method
[self schedule:#selector(flipOrientation:) interval:30.0];
this should do what you are asking for however i strongly suggest, as nash said, that you rotate instead of setting the orientation. You can rotate your main layer, or gameScene.. it will be more responsive and you can have control over how it animates. You can do it the same way as above by scheduling but instead of setting device Orientation just rotate your layer.... hope this helps

New View when device is rotated

I want to call "presentmodalviewcontroller" when the iPhone / iPod Touch is rotated to landscape mode with a flip animation. When it gets rotated back to portrait, I want to present the first view again, again with the flip animation.
Weren't able to find something working on the web :(
I'm sure you can help me :)
Thanks a lot !
Sebastian
Try listening for the UIDeviceOrientationDidChangeNotification notification:
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
When you get on it, present your controller.
In your UIViewController, accept all interface orientations:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
And your controller will start receiving rotation messages, like:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
and
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
Where you can react to rotation and do things like present/dismiss modal viewcontrollers.

Opening AFOpenFlowView already in landscape mode

I'm using the open source CoverFlow replacement from here: http://fajkowski.com/blog/2009/08/02/openflow-a-coverflow-api-replacement-for-the-iphone/
When I detect that a certain view has gone from portrait to landscape mode, I instantiate an AFCoverFlowView and push it onto the navigation stack.
If I do so in response to
(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
The cover flow view comes up as though the phone were still in portrait mode.
If I push the view in response to
(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
it works perfectly - the view comes up in landscape mode with the phone in landscape mode
Unfortunately, the device doesn't reliable get willRotateToInterfaceOrientation messages. I have tried making sure that
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
is in loadView but that doesn't help with the notificiations.
So, my questions are:
Is there a way to reliably get willRotateToInterfactOrientation?
if not
How do I instruct AFCoverFlowView to come up in landscape mode (if the device is already in landscape mode)
I did a transformation on the flowView from the controller class like this:
CGAffineTransform transform = self.view.transform;
transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
self.view.transform = transform;
Which worked well enough for my purposes.

Hide an UITabBar when Orientation change

I have a quite simple question but the answer is not so easy.
I want to hide a UITabBar when my orientation change.
I looked 2 ways :
Frame way
myAppDelegate.tabBarController.tabBar.frame = CGRectMake(<<bottomOfScreen>>);
Works fine but I have a blank area, so tried to play with tabBarController.view.frame et myViewController.view.frame but I didn't get any good result.
Navigation Controller Way
myOtherVC.hideTabBarWhenPushed = YES;
[self.navigationController pushViewController:myOtherVC animated:NO];
Works but isn't a good solution for my app
Update:
[appDelegate.tabBarController.view removeFromSuperview];
[self.view removeFromSuperview]; [appDelegate.window addSubview:self.view];
self.view.frame = CGRectMake(0,0,480,320);
Works fine but doesn't autorotate anymore (and of course, I didn't change the shouldAutorotate and it always returns YES)
How can I hidde my tabBar and make the current view taking its space ?
Thanks
You can use the current solution combined with:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didRotate:) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
to detect rotation. (I think that you combine this with view.transform = CGAffineTransformMakeRotation to make it rotate...?)
Two ways I think you can easily do this would be:
to reload the objects back into the tabBar controller - with the hidesBottomBarWhenPushed set to YES for the viewControllers you want to be hidden.
The other option would be to just make your view the only view for the window when the phone is rotated and then put the tabBarController.view back in the window when the phone is rotated back
Hope this helps