i have app has 2 view controllers. first viewcontroller should in portrait , it's ok, when i'm loading second view controller, not make app orientation landscape... problem ios 6.
i have tried found on so.
using [[uiapplication sharedapplication] setstatusbarorientation:uiinterfaceorientationlandscaperight animated:no]; on viewwillappear , viewdidload,
and also:
- (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation { if (interfaceorientation == uiinterfaceorientationportrait) { return (interfaceorientation == uiinterfaceorientationlandscaperight); } else { return (interfaceorientation == uiinterfaceorientationlandscaperight); } } -(bool)shouldautorotate { return yes; } - (uiinterfaceorientation)preferredinterfaceorientationforpresentation { return uiinterfaceorientationlandscaperight; } -(nsinteger)supportedinterfaceorientations{ return uiinterfaceorientationmasklandscaperight; }
add these code in 2nd view controller's viewdidload method transform view landscape :
[self rotatecontroller:self degrees:-90]; [[uiapplication sharedapplication] setstatusbarorientation:uiinterfaceorientationlandscapeleft animated:no]; //set according 3.5 , 4.0 inch screen in landscape mode [self.view setbounds:cgrectmake(0, 0, 480, 320)]; add rotatecontroller method :
-(void) rotatecontroller:(uiviewcontroller *)controller degrees:(nsinteger)adgrees { uiscreen *screen = [uiscreen mainscreen]; if(adgrees>0) controller.view.bounds = cgrectmake(0, 0, screen.bounds.size.height, screen.bounds.size.width); else { controller.view.bounds = cgrectmake(0, 0, screen.bounds.size.width, screen.bounds.size.height); } controller.view.transform = cgaffinetransformconcat(controller.view.transform, cgaffinetransformmakerotation(degrees_to_radians(adgrees))); } now in viewwilldisappear's method transform view protrait . add these:
[self rotatecontroller:self degrees:90]; [[uiapplication sharedapplication] setstatusbarorientation:uiinterfaceorientationportrait animated:no]; //set according 3.5 , 4.0 inch screen in protrait mode [self.view setbounds:cgrectmake(0, 0, 320, 480)]; also orientation methods should these if not added add these :
- (bool)shouldautorotate { //make view landscape on start return no; } - (nsuinteger)supportedinterfaceorientations { return uiinterfaceorientationmasklandscapeleft; } - (uiinterfaceorientation)preferredinterfaceorientationforpresentation { return uiinterfaceorientationlandscapeleft; } edit : add these macro radian
#define degrees_to_radians(angle) ((angle) / 180.0 * m_pi)
Comments
Post a Comment