iphone: rotation in mpmovieplayercontroller?

做~自己de王妃 提交于 2019-12-08 12:04:23

问题


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


}

回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/5528613/iphone-rotation-in-mpmovieplayercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!