这是我想要实现的目标,它将是对设备的旋转发送动作......
关键是我有360播放器,我希望视频只在设备处于横向状态时启动。如果它是纵向的,我想要显示一条消息"以横向方式旋转您的设备以启动",当用户旋转设备时,视频播放。
到目前为止,是我的代码:
- (IBAction)test:(id)sender forEvent:(UIEvent *)event {
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation ]== UIDeviceOrientationLandscapeRight)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo1" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:@"HTY360PlayerVC" bundle:nil url:url];
[videoController VRMode:true];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil];
}
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown )
{
NSLog(@"UIDeviceOrientationPortrait");
}
}
此代码的问题不仅仅是在Sent Event中的TouchUp Inside上触发。 。 。无论如何让这个动作从轮换开始?
感谢您的帮助!
EDIT ---
以下是ASWELL:
- (IBAction)test:(id)sender forEvent:(UIEvent *)event {
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation ]== UIDeviceOrientationLandscapeRight)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo1" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:@"HTY360PlayerVC" bundle:nil url:url];
[videoController VRMode:true];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil];
}
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown )
{
NSLog(@"UIDeviceOrientationPortrait");
}
}
答案 0 :(得分:0)
你试过吗
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
答案 1 :(得分:0)
尝试将代码放入其中:
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
}
并在UIViewController
中写下此方法。当设备(真正的接口)旋转时调用此方法;如果您想在旋转界面之前执行某些操作,请使用willRotateFromInterfaceOrientation