In iOS 6 shouldAutorotateToInterfaceOrientation
funktioniert es nicht, aber es funktioniert gut in iOS 5.0
oder 5.1
.
Was muss ich in iOS 6
..__ ändern? Hier ist mein Code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([[[SampleApplicationAppDelegate instance].callInfoDictionary valueForKey:IS_CHAT] isEqualToString:NO_RESPONSE])
{
int nAngle = 0;
BOOL bRet = NO;
switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
nAngle = 90;
bRet = YES;
NSLog(@".......Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
NSLog(@"Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
break;
case UIInterfaceOrientationPortraitUpsideDown:
nAngle = 270;
bRet = YES;
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case UIInterfaceOrientationLandscapeLeft:
nAngle = 0;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
break;
case UIInterfaceOrientationLandscapeRight:
nAngle = 180;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
default:
break;
}
return bRet;
}
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
return YES;
return NO;
}
als ich nach diesem Orientierungsproblem suche, fand ich das alles
aber nichts funktioniert für mich :( Bitte helfen .....
EDIT: Dies geschieht, weil Apple die Verwaltung der Ausrichtung von UIViewController
geändert hat. In iOS6 wird die Ausrichtung anders behandelt. In iOS6 ist die shouldAutorotateToInterfaceOrientation
-Methode veraltet. View-Controller (z. B. UINavigationController
) konsultieren ihre Kinder nicht, um zu bestimmen, ob sie automatisch rotieren sollen. Standardmäßig sind die unterstützten Schnittstellenorientierungen einer App und eines View-Controllers für das iPad idiom und UIInterfaceOrientationMaskAll
für das iPhone-Idiom auf UIInterfaceOrientationMaskAllButUpsideDown
gesetzt.
Wenn Sie möchten, dass eine bestimmte Ansicht in die gewünschte Ausrichtung geändert wird, müssen Sie eine Art Unterklasse oder Kategorie erstellen und die Autorotationsmethoden überschreiben, um die gewünschte Ausrichtung zurückzugeben.
Fügen Sie diesen Code in Ihren Root-View-Controller ein. Dies hilft der UIViewController
, ihre Orientierung zu bestimmen.
//RotationIn_IOS6 is a Category for overriding the default orientation.
@implementation UINavigationController (RotationIn_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
Nun müssen Sie zur Orientierung folgende Methoden (in iOS6 eingeführt) in viewController implementieren
- (BOOL)shouldAutorotate
{
//returns true if want to allow orientation change
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations
{
//decide number of origination tob supported by Viewcontroller.
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//from here you Should try to Preferred orientation for ViewController
}
Und fügen Sie Ihren Code in die untenstehende Methode ein. Bei jeder Änderung der Geräteorientierung Wird diese Methode aufgerufen:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration
{
if([[[SampleApplicationAppDelegate instance].callInfoDictionary valueForKey:IS_CHAT] isEqualToString:NO_RESPONSE])
{
int nAngle = 0;
BOOL bRet = NO;
switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
nAngle = 90;
bRet = YES;
NSLog(@".......Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
NSLog(@"Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
break;
case UIInterfaceOrientationPortraitUpsideDown:
nAngle = 270;
bRet = YES;
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case UIInterfaceOrientationLandscapeLeft:
nAngle = 0;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
break;
case UIInterfaceOrientationLandscapeRight:
nAngle = 180;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
default:
break;
}
}
Edit: Überprüfen Sie Ihr Fenster. Sie müssen den Controller unter rootViewController
anstelle von addSubview
wie unten angegeben hinzufügen
self.window.rootViewController=viewController;
Für weitere Informationen hier s ist ein Artikel über iOS6.0 Beta 2 OTA.
Ich hoffe das war hilfreich.
Wie ich dieses Problem behoben habe, bestand darin, die folgende Zeile zu ersetzen, wenn meine App in Delegate Class startet
window addSubview: navigationController.view
mit
window.rootViewController = navigationController
Nachdem ich diese Änderung vorgenommen hatte, begann meine App mit dem Drehen des Bildschirms
Dies ist darauf zurückzuführen, dass Apple die von ios6 verwendete Methode als missachtet empfohlen hat. Verwenden Sie stattdessen diese Methoden
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0);
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
// Returns interface orientation masks.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0);
Ich habe dieses Problem gelöst, benutze es einfach
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(![AppDelegate instance])
return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
if([[[AppDelegate instance].callInfoDictionary valueForKey:IS_CHAT] isEqualToString:NO_RESPONSE])
{
int nAngle = 0;
BOOL bRet = NO;
switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
{
nAngle = 90;
bRet = YES;
NSLog(@".......Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"6.0" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending)
{
// OS version >= 6.0
NSLog(@"AMI iOS 6 er device");
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
}
else
{
// OS version < 6.0
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
}
NSLog(@"Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
NSLog(@"-->%s %d",__FUNCTION__,__LINE__);
break;
}
case UIInterfaceOrientationPortraitUpsideDown:
{
nAngle = 270;
bRet = YES;
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"6.0" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending)
{
// OS version >= 6.0
NSLog(@"AMI iOS 6 er device");
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
}
else
{
// OS version < 6.0
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
}
break;
}
case UIInterfaceOrientationLandscapeLeft:
nAngle = 0;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
break;
case UIInterfaceOrientationLandscapeRight:
nAngle = 180;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
default:
break;
}
return bRet;
}
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
return YES;
return NO;
}
bitte versuchen Sie es hier, es wird für Sie hilfreich sein.
schreiben Sie Code in Ihre Viewcontroller-Klasse
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
Suchen Sie dann in appdelegate diese Zeile [window addSubview: viewController.view] Und ersetzen Sie diese durch window.rootViewController = viewController;
beifall wird es funktionieren. Seine einfache Lösung für iOS 6
das hat für mich funktioniert
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait) {
// your code for portrait mode
}
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown;
}