عرض الموضع بشكل غير صحيح عند ضبطه على وضع المناظر الطبيعية

StackOverflow https://stackoverflow.com/questions/2086214

سؤال

يعتمد تطبيق iPhone الخاص بي على التنقل ويحتوي على الكثير من المشاهدات التي تشير إلى الصورة فقط وعرض واحد فقط لمشاهدة الصور. لذلك أرغب في إجبار هذا العرض على المناظر الطبيعية فقط للتدوير تلقائيًا إلى Lanscape حتى لو تم وضع الجهاز في وضع الصورة.

إذن هذا ما فعلته في وحدة تحكم هذا العرض:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
}

- (void)viewWillAppear:(BOOL)animated
{
 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
 [self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];

 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

 _originalTransform = [[appDelegate navigationController].view transform];
 _originalBounds = [[appDelegate navigationController].view bounds];
 _originalCenter = [[appDelegate navigationController].view center];

 CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
 landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +100.0);

 [[appDelegate navigationController].view setTransform:landscapeTransform];

 [appDelegate navigationController].view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
 [appDelegate navigationController].view.bounds  = CGRectMake(0.0, 0.0, 480.0, 320.0);
 [appDelegate navigationController].view.center  = CGPointMake (240.0, 160.0);

 [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
 }
}

- (void)viewWillDisappear:(BOOL)animated
{ 
 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
 [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];

 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
 [[appDelegate navigationController].view setTransform:_originalTransform];
 [[appDelegate navigationController].view setBounds:_originalBounds];
 [[appDelegate navigationController].view setCenter:_originalCenter];

 [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait; 
}

لقد حصلت الآن على هذا العرض الذي يظهر دائمًا في وضع Lanscape. ولكن هناك مشكلة واحدة. يتم وضع هذا العرض بشكل غير صحيح كما هو موضح في هذه لقطة الشاشة.

حاولت ضبط الإطار يدويًا بعد الدوران لكنه لم يساعد. كما أنني لم أجد دليلًا كاملاً كيفية تعيين عرض واحد ليكون المناظر الطبيعية فقط. الرجاء مساعدتي في هذه المشكلة.

هل كانت مفيدة؟

المحلول

تحقق من هذا الرجل بريد. تحتاج بشكل أساسي إلى التحول حول وسط النافذة. يبدو أنك قد تحتاج أيضًا إلى تدوير شريط الحالة.

تتمثل طريقة مختلفة في استخدام uidevice setDeviceorientation ، ولكن هذه واجهة برمجة تطبيقات خاصة وبالتالي ليست حلًا رائعًا.

نصائح أخرى

حاول استخدام هذه الطريقة بعد تطبيق التحول:

[self.view sizeToFit];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top