I'm trying to change the views of the turn, because my views should differ significantly from portrait to landscape. Now the code that I use works once, after which the application freezes when trying to turn back. Any direction does not matter. For example: if I am in the Landscape and turn to the portrait, everything works fine, until I return to the landscape, it freezes and does nothing.
Here is the code I use to achieve this
In my viewDidLoad method
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
Then I call it for rotation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIDeviceOrientationLandscapeLeft) ||
(orientation == UIDeviceOrientationLandscapeLeft))
{
[self.view addSubview:landScapeView];
}
if ((orientation == UIDeviceOrientationLandscapeRight) ||
(orientation == UIDeviceOrientationLandscapeRight))
{
[self.view addSubview:landScapeView];
}
else if ((orientation == UIDeviceOrientationPortrait ||
(orientation == UIDeviceOrientationPortrait))
{
[self.view addSubview:portrait];
}
else if ((orientation == UIDeviceOrientationPortraitUpsideDown ||
(orientation == UIDeviceOrientationPortraitUpsideDown))
{
[self.view addSubview:portrait];
}
}
source
share