objective c - Unable to force device to change UIOrientation -
i have vc modally adds image picker controller, , goes same vc when pic selected. after obtain image via pickercontroller, add image screen, , want device automatically change landscape if pic landscape, , portrait if pic portrait.
i have unsuccessfully tried both of these approaches force device landscape
1. [[uiapplication sharedapplication] setstatusbarorientation:uiinterfaceorientationlandscapeleft]; 2. [uiviewcontroller attemptrotationtodeviceorientation]; -(nsuinteger)supportedinterfaceorientations { if (!isportrait) //isportrait false when pic landscape return uiinterfaceorientationmasklandscape; }
alternatively, i'm wondering if it's best instantiate separate vc picture. i've avoided far after question
my guess have call [[uiapplication sharedapplication] setstatusbarorientation:
inside viewwillappear:
method of viewcontroller presenting uiimagepickercontroller
.
for need know first image orientation, can this:
- (bool)shouldautorotate { return no; } - (void) viewdidappear:(bool)animated { [super viewdidappear:animated]; if(myorientation>0) [uiapplication sharedapplication].statusbarorientation = myorientation; } - (void)presentpicker { uiimagepickercontroller* imgpicker = [[uiimagepickercontroller alloc] init]; imgpicker.delegate = self; [self presentviewcontroller:imgpicker animated:yes completion:nil]; } - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { uiimage* image = [info objectforkey:@"uiimagepickercontrolleroriginalimage"]; if(image.size.width>image.size.height) myorientation = uiinterfaceorientationlandscapeleft; else myorientation = uiinterfaceorientationportrait; [picker dismissviewcontrolleranimated:yes completion:nil]; }
also, don't forget set initial , supported interface orientations in plist (the first of supported orientations has equal initial orientation)
Comments
Post a Comment