objective c - iOS 6.0+ autorotation for youtube embedded video -


i want support vertical orientation throughout view controllers of ios app. however, embed youtube video in 1 of view controllers, , when video selected take full screen, want user able orient his/her phone horizontally video expands take full screen.

edit: tried using following code autorotate in ios 6 has strange behaviour:

- (nsuinteger) application:(uiapplication *)application supportedinterfaceorientationsforwindow:(uiwindow *)window {  return self.fullscreenvideoisplaying ?     uiinterfaceorientationmaskallbutupsidedown :     uiinterfaceorientationmaskportrait; 

}

and in view controller presents uiwebview/youtube frame, have code in viewdidload:

[[nsnotificationcenter defaultcenter]      addobserver:self      selector:@selector(windownowvisible:)      name:uiwindowdidbecomevisiblenotification      object:self.view.window ];  - (void)windownowvisible:(nsnotification *)notification {     appdelegate* appdelegate = (appdelegate*)[[uiapplication sharedapplication] delegate];     appdelegate.fullscreenvideoisplaying = !(appdelegate.fullscreenvideoisplaying); } 

however, when user presses done on fullscreen youtube video, if he/she still has phone horizontally, presenting view controller stays horizontal (i want present view controller portrait). it's race on fullsreenvideoisplaying variable isn't updating fast enough presenting view controller portrait.

any feedback on how achieve appreciated.

thanks!

figured out solution molding few solutions i've found on stackoverflow.

instead of using notification

 [[nsnotificationcenter defaultcenter]       addobserver:self       selector:@selector(windownowvisible:)       name:uiwindowdidbecomevisiblenotification       object:self.view.window  ]; 

i use following notifications

     [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(youtubestarted:) name:@"uimovieplayercontrollerdidenterfullscreennotification" object:nil];      [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(youtubefinished:) name:@"uimovieplayercontrollerwillexitfullscreennotification" object:nil]; 

with implementations

 -(void) youtubestarted:(nsnotification*) notif {      appdelegate* appdelegate = (appdelegate*)[[uiapplication sharedapplication] delegate];      appdelegate.fullscreenvideoisplaying = yes; }  -(void) youtubefinished:(nsnotification*) notif {      appdelegate* appdelegate = (appdelegate*)[[uiapplication sharedapplication] delegate];      appdelegate.fullscreenvideoisplaying = no;  } 

and in appdelegate, have

 - (nsuinteger)application:(uiapplication *)application supportedinterfaceorientationsforwindow:(uiwindow *)window{      nsuinteger orientations = uiinterfaceorientationmaskportrait;      if (self.fullscreenvideoisplaying) {          return uiinterfaceorientationmaskallbutupsidedown;      }      else {                  if(self.window.rootviewcontroller){              uiviewcontroller *presentedviewcontroller = [[(uinavigationcontroller *)self.window.rootviewcontroller viewcontrollers] lastobject];              orientations = [presentedviewcontroller supportedinterfaceorientations];      } return orientations;  } 

and in view controllers, have

 -(bool) shouldautorotate {      return no;  }  -(nsuinteger)supportedinterfaceorientations{      return uiinterfaceorientationmaskportrait;  }  - (uiinterfaceorientation)preferredinterfaceorientationforpresentation{      return uiinterfaceorientationportrait;  } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -