Judge the screen vertically. http://www.cocoachina.com/ask/questions/show/121301
//Self.cameraview is the camera view-(Nsuinteger) supportedinterfaceorientations{uiinterfaceorientation e=[[UIApplication sharedapplication] statusbarorientation]; if(E = =uiinterfaceorientationlandscapeleft) { if(Self.cameraview) {Self.cameraView.transform= Cgaffinetransformmakerotation (- the* M_PI)/180.0f); } }Else if(E = =uiinterfaceorientationlandscaperight) { if(Self.cameraview) {Self.cameraView.transform= Cgaffinetransformmakerotation (( the* M_PI)/180.0f); } } return(Uiinterfaceorientationmasklandscape);} - (void) viewdidload{[Super Viewdidload]; //Do any additional setup after loading the view. //M_bscreen is a bool type, judging the screen. if([[[[Uidevice currentdevice]systemversion]floatvalue] >=8.0) {BOOL M_bscreen=NO; Uiinterfaceorientation e=[[UIApplication sharedapplication] statusbarorientation]; if(E = =uiinterfaceorientationlandscapeleft) {M_bscreen=NO; }Else if(E = =uiinterfaceorientationlandscaperight) {M_bscreen=YES; } if([[Uidevice Currentdevice] Respondstoselector: @selector (setorientation:)]) {NSNumber*num = [[NSNumber alloc] Initwithint: (m_bscreen?Uiinterfaceorientationlandscaperight:uiinterfaceorientationlandscapeleft)]; [[Uidevice Currentdevice] Performselector: @selector (setorientation:) Withobject: (ID) num]; [Uiviewcontroller attemptrotationtodeviceorientation];//This line of code is key} SEL Selector=nsselectorfromstring (@"setorientation:"); Nsinvocation*invocation =[Nsinvocation Invocationwithmethodsignature:[uidevice instancemethodsignatureforselector:selector]; [Invocation setselector:selector]; [Invocation Settarget:[uidevice Currentdevice]; intVal =m_bscreen?Uiinterfaceorientationlandscaperight:uiinterfaceorientationlandscapeleft; [Invocation setargument:&val Atindex:2]; [Invocation invoke]; } }
How to get camera view:
#pragmaMark Uinavigationcontrollerdelegate-(void) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Willshowviewcontroller: (UIViewController *) Viewcontroller animated: (BOOL) animated{if([[[[Uidevice currentdevice]systemversion]floatvalue] >=8.0) {UIView*plcameraview=[self FindView:viewController.view Withname:@"Plimagepickercameraview"]; Nsarray*svarray =[Plcameraview subviews]; Self.imagePickerController.cameraView = svarray[0]; for(inti =1; i < Svarray.count; i++) {//i:0 camera 1 Photo screen 2 re-pat interface if(i = =1) {Nsarray*arr = [svarray[1] subviews]; for(inti =0; i < Arr.count; i++) { if(i = =9) {//i:1 front-facing camera switch[arr objectatindex:i] Setalpha:0.0f]; } } } } }Else if([[[[Uidevice currentdevice]systemversion]floatvalue] >=7.0) {UIView*plcameraview=[self FindView:viewController.view Withname:@"Plcameraview"]; Nsarray*svarray =[Plcameraview subviews]; for(inti =1; i < Svarray.count; i++) {//i:0 camera 1 Photo screen 2 re-pat interface if(i = =1) {Nsarray*arr = [svarray[1] subviews]; for(inti =0; i < Arr.count; i++) { if(i = =1) {//i:1 front-facing camera switch[arr objectatindex:i] Setalpha:0.0f]; } } } } }}#pragmaMark Get/show the UIView we want//Find The view we want in camera structure.-(UIView *) Findview: (UIView *) Aview withname: (NSString *) name{Class cl= [Aviewclass]; NSString*desc =[cl description]; if([name Isequaltostring:desc])returnAview; for(Nsuinteger i =0; i < [aview.subviews count]; i++) {UIView*subview =[Aview.subviews objectatindex:i]; SubView=[self findview:subview withname:name]; if(SubView)returnSubView; } returnNil;}
IOS8 screen Rotation problem