【问题标题】:Use accelerometer in my movieplayer app在我的电影播放器​​应用程序中使用加速度计
【发布时间】:2012-01-24 02:35:35
【问题描述】:

我有一个应用程序可以播放来自网络服务器的视频,但它只是横向播放。我希望我的应用程序使用加速度计以横向和纵向播放我的视频。我希望我的视频播放功能看起来像 iPhone 中的 youtube 应用程序。谁能帮助我如何做到这一点?谢谢

【问题讨论】:

    标签: iphone youtube mpmovieplayercontroller accelerometer


    【解决方案1】:

    为此,您不需要加速度计。相反,您收听来自 UIDevice 单例实例的通知,这些通知在方向更改时发送。在您的“应用程序 didFinishLaunching withOptions”方法中,键入:

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

    然后创建这个方法来处理方向变化:

    - (void)deviceOrientationDidChange {
    int orientation = (int)[[UIDevice currentDevice]orientation];
    switch (orientation) {
        case UIDeviceOrientationFaceDown:
            NSLog(@"UIDeviceOrientationFaceDown" );
            // handle orientation
            break;
        case UIDeviceOrientationFaceUp:
            NSLog(@"UIDeviceOrientationFaceUp" );
            // handle orientation
            break;
        case UIDeviceOrientationLandscapeLeft:
            NSLog(@"UIDeviceOrientationLandscapeLeft" );
            // handle orientation
            break;
        case UIDeviceOrientationLandscapeRight:
            NSLog(@"UIDeviceOrientationLandscapeRight" );
            // handle orientation
            break;
        case UIDeviceOrientationPortrait:
            NSLog(@"UIDeviceOrientationPortrait" );
            // handle orientation
            break;
        case UIDeviceOrientationPortraitUpsideDown:
            NSLog(@"UIDeviceOrientationPortraitUpsideDown" );
            // handle orientation
            break;
        case UIDeviceOrientationUnknown:
            NSLog(@"UIDeviceOrientationUnknown" );
            // handle orientation
            break;
    
        default:
            break;
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2010-09-25
      • 1970-01-01
      相关资源
      最近更新 更多