2016-11-17 3 views
0

вот что я пытаюсь достичь, было бы направить действия на вращении устройства ...Отправить Действие на вращении прошивки устройства

точки я имею 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"); 
} 

} 

Проблема этого кода, чем срабатывают только на TouchUp Внутри в Sent Event. , , во всяком случае, чтобы действие начиналось с вращения?

Спасибо за вашу помощь!

EDIT ---

TRYIED СЛЕДУЮЩИЙ 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

Вы пробовали

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
+0

Кому это следует добавить? под первой линией IBAction? – tibewww

+0

включите этот метод в класс ура – vaibby

+0

Хм, я не понимаю, я только начинаю в iOS Dev. Я отредактировал вопрос с добавлением кода, который вы сказали, но он покажет мне ошибку «USe on undercalified identifier shouldautorotatetointerfaceorientation» Любая идея? Спасибо за вашу помощь, очень ценю – tibewww

0

Попробуйте поместить свой код внутри:

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 

} 

и написать это методов в вашем UIViewController. Этот метод вызывается, когда устройство (интерфейс действительно) повернуто; если вы хотите что-то сделать до поворота интерфейса, используйте willRotateFromInterfaceOrientation

Смежные вопросы