UiimagePickerController في المناظر الطبيعية
-
21-09-2019 - |
سؤال
لقد كنت أبحث عن إجابة على هذا ، لكن لا يمكنني التوصل إلى أي شيء. على ما يبدو ، جعل iPhone SDK 3.0 من الممكن عرض UiImagePickerController في وضع المناظر الطبيعية - لكنني لا أجد أي طريقة تسمح بذلك. أعتقد أنه إذا كان التطبيق في المناظر الطبيعية افتراضيًا ، فسيقوم تلقائيًا بضبط وحدة تحكم الصورة ، لكن هذا لا يعمل بالنسبة لي.
شكرا على اي مساعدة!
المحلول
لم أتحقق مما إذا كان هذا غير قانوني ، لكنه نجح بالنسبة لي. إذا كنت تريد أن تبدأ uiimagepickontroller (والبقاء) في رمز اتجاه المناظر الطبيعية:
//Initialize picker
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//set Device to Landscape. This will give you a warning. I ignored it.
//warning: 'UIDevice' may not respond to '-setOrientation:'
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
//Set Notifications so that when user rotates phone, the orientation is reset to landscape.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//Refer to the method didRotate:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
//Set the picker source as the camera
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Bring in the picker view
[self presentModalViewController:picker animated:YES];
طريقة didrotate:
- (void) didRotate:(NSNotification *)notification
{
//Maintain the camera in Landscape orientation
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
نصائح أخرى
لا حاجة للفئة الفرعية. ببساطة تجاوز modalPresentationStyle
منشأه.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.modalPresentationStyle = UIModalPresentationFormSheet;
[viewController presentViewController:picker animated:YES completion:NULL];
إذا كنت بحاجة فقط للتخلص من محاولة التحذير
@interface UIDevice ()
-(void)setOrientation:(UIDeviceOrientation)orientation;
@end
لقد طورت فئة UiimagePicker في وضع المناظر الطبيعية. يعمل بشكل رائع للتطبيقات التي طورتها: آمل أن يكون من أجلك أيضًا:
جيثب: https://github.com/imaginaryunit/ioslandscapetherediMagePicker.git
لديّ تطبيق All-Landscape باستخدام UiimagePickerController أيضًا. يرجى الإشارة إلى أنه إذا قمت بالاتصال بـ UIImagePickerController في وضع المناظر الطبيعية ، فمن الممكن رفض تطبيقك من قبل فريق Apple Review.
لقد ابتكرت عملًا بسيطًا حول هذه المسألة التي تجعل مندوبًا لا بد من استخدام. توافق Apple على هذه الطريقة لتطبيق All-Landscape.
يرى هنا للحصول على التفاصيل والرمز المصدر الكامل للمشروع القابل للتنزيل.
جعل فئة من uinavigationcontroller وأضف هذه الطريقة
- (BOOL)shouldAutorotate
{
return NO;
}
الفئة الفرعية UIImagePickerController
والتجاوز modalPresentationStyle
على النحو التالي:
- (UIModalPresentationStyle)modalPresentationStyle
{
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
return UIModalPresentationFormSheet;
}
return [super modalPresentationStyle];
}
إن Picker-Picker عبارة عن ورقة أشكال الآن ولم تعد في وضع كامل الشاشة ، ولكنها تبدو جيدة في وضع المناظر الطبيعية. يجب أن يكون هذا آمنًا للتطبيق.
هذا يعمل للمعرض ، وليس لالتقاط الصور.
لقد حللت هذه المشكلة على النحو التالي: بعد كل تغيير في الاتجاه ، أقوم بإعادة إنشاء منتقي بسيط. جرب هذا. بشكل مختلف هو ملتوية جدا ...
أقوم بتطوير فصل يحاول أفضل ما في وضعه في وضع المناظر الطبيعية. تحقق من ذلك على جيثب: Racameracontroller