В моем приложении у меня есть Домой с несколькими кнопками. Каждая кнопка открывает отдельный вид. В каждом представлении, если я помещаю устройство в альбом, отображается вид справки. Все работает отлично, за исключением того, что в любом моем представлении, если я помещу iPhone, как заложить на стол (я не знаю, как лучше использовать ...) приложение выходит из этого представления и возвращается к первому виду, дом. Вот мой код:Как перехватить поворот iPhone
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)name:@"UIDeviceOrientationDidChangeNotification"
object:nil];
[self performSelector:@selector (ritardo) withObject:nil afterDelay:5.0f];
}
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIInterfaceOrientationPortrait)
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.portraitView;
}
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation
== UIInterfaceOrientationLandscapeRight)
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.landscapeView;
}
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
}
-(void) ritardo {
ruota.image = [UIImage imageNamed:@"RuotaPerAiuto.png"];
}
- (void)viewDidUnload
{
[self setPortraitView:nil];
[self setLandscapeView:nil];
[self setRuota:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
Привет надеюсь, что вы можете помочь мне
EDIT: я изменил - (Недействительными) orientationChanged: (NSNotification *) объект {таким образом:
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationFaceUp)// || deviceOrientation ==
UIDeviceOrientationFaceDown)
{
return;
}
if (deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation ==
UIInterfaceOrientationPortraitUpsideDown)
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.portraitView;
}
else
if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation ==
UIInterfaceOrientationLandscapeRight)
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.landscapeView;
}
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
}
Теперь, если я нахожусь в портрете и получаю iPhone в лицо. Позиция позиции работает хорошо. Но когда я меняю позицию с faceUp на портрет, он возвращается к дому ...
Спасибо за ваш ответ. Я только что изменил метод orientationChanged в соответствии с вашим предложением, но он все тот же. Может быть, я не могу точно объяснить позицию iPhone, с которой я бы хотел справиться: может ли это выглядеть так? – Enzoses
Хорошо! Теперь он отлично работает, спасибо! – Enzoses
Нет ... Я говорил слишком рано ... Теперь он возвращается к дому, когда позиция iPhone возвращается из faceUp в Portrait :(. Я изменил метод orientationChanged, добавив if (deviceOrientation == UIDeviceOrientationFaceUp) // также пытался с || deviceOrientation == UIDeviceOrientationFaceDown) {return;} – Enzoses