【问题标题】:iphone: rotation in mpmovieplayercontroller?iphone:在 mpmovieplayercontroller 中旋转?
【发布时间】:2011-04-03 09:00:40
【问题描述】:

我在 mpmovieplayercontroller 顶部有一个小视图。当它不是全屏时,我可以将视图的框架调整为方向(当设备旋转时)。但是当我进入全屏模式时,虽然我设法呈现视图,但当设备旋转时我不再能够保持正确的帧。看起来在全屏模式下,系统只是在状态栏和电影播放器​​上使用 CGAffineTransformRotate。如何应用此 CGAffineTransformRotate 来正确旋转我的视图?


编辑:

好的,所以我更新了代码,以便在改变 mpmovieplayercontroller 的方向后沿 X 轴旋转 90%,但视图在第一次旋转后就消失了。这是我的代码:

- (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


}

【问题讨论】:

    标签: iphone ipad rotation mpmovieplayercontroller cgaffinetransform


    【解决方案1】:

    我不确定这是否一定是 正确 的方法(我猜你正在向 MPMoviePlayerController 视图添加子视图?),但你似乎是after 是电影播放器​​全屏旋转时的回调,因此您可以调整自己的自定义视图。

    您可以在自定义视图上注册轮播通知,然后每次收到回调时都会自行调整。您注册轮换通知如下:

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(layoutViewForOrientation:)
        name:UIDeviceOrientationDidChangeNotification
        object:nil];
    

    您应该记得endGeneratingDeviceOrientationNotifications 并在您完成全屏模式后移除您的通知观察者。

    【讨论】:

    • +1 表示正确答案。不过还有一个补充 - 为了保持自定义子视图的正确尺寸,只需在应用仿射变换后再次应用其原始帧(无需考虑此时切换的坐标)。
    • 是的,我很清楚如何检测方向变化。我的问题是转换。您能否发布一些关于如何基于旋转 mpmovieplayercontroller(全屏)实际旋转视图的代码?
    • 如何旋转视图取决于其内容,但您可能希望 a) 检查当前方向,然后 b) 使用适当方向的变换旋转该视图。如果您不确定如何应用转换本身,请查看以下问题:stackoverflow.com/questions/242424/…
    【解决方案2】:

    好的,

    所以全屏覆盖 mpmovieplayercontroller 的最佳方式是这样:

    [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] addSubview:mySubview]
    

    这有点老套,但合法。它为您提供了一种处理旋转的简单方法(而不是使用转换)。

    【讨论】:

    • 这不是最好的方法,而是一种可能的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多