EIDT:固定。它看起来像是一个模拟器问题。 由于GabrieliPhone启动方向(再次!)
一个模拟器,我得到只此:
--- UIDeviceOrientationDidChangeNotification -> [<UIDevice: 0x7577d30>] {
但我得到的新通知的整体筏在设备上...
--- UIDeviceOrientationDidChangeNotification -> [<UIDevice: 0x1dd5a0c0>] {
--- UIApplicationDidEndResumeAnimationNotification -> [<UIApplication: 0x1dd63500>] (null)
--- UIDeviceOrientationDidChangeNotification -> [<UIDevice: 0x1dd5a0c0>] {
--- _UIApplicationDidBeginIgnoringInteractionEventsNotification -> [<UIApplication: 0x1dd63500>] (null)
--- UIWindowWillRotateNotification -> [<UIWindow: 0x1e866b40; frame = (0 0; 320 568); layer = <UIWindowLayer: 0x1e866ad0>>] {
--- UIApplicationWillChangeStatusBarOrientationNotification -> [<UIApplication: 0x1dd63500>] {
--- UIApplicationWillChangeStatusBarFrameNotification -> [<UIApplication: 0x1dd63500>] {
--- UIViewAnimationDidCommitNotification -> [UIViewAnimationState] {
--- UIApplicationDidChangeStatusBarOrientationNotification -> [<UIApplication: 0x1dd63500>] {
--- UIApplicationDidChangeStatusBarFrameNotification -> [<UIApplication: 0x1dd63500>] {
--- UIWindowWillAnimateRotationNotification -> [<UIWindow: 0x1e866b40; frame = (0 0; 320 568); layer = <UIWindowLayer: 0x1e866ad0>>] {
--- UIViewAnimationDidCommitNotification -> [UIViewAnimationState] {
--- UIViewAnimationDidStopNotification -> [<UIViewAnimationState: 0x1e8692f0>] {
--- _UIApplicationDidEndIgnoringInteractionEventsNotification -> [<UIApplication: 0x1dd63500>] (null)
--- UIWindowDidRotateNotification -> [<UIWindow: 0x1e866b40; frame = (0 0; 320 568); layer = <UIWindowLayer: 0x1e866ad0>>] {
--- UIViewAnimationDidStopNotification -> [<UIViewAnimationState: 0x1e867ea0>] {
哦...
我真的把我的头发拉在这个上面。我在这里看到了许多有关S.O.的问题。但找不到为我工作的人。
我正在使用最简单的例子,Xcode 4.6.2,新项目,空应用程序。
结果是,如果应用程序在纵向中启动,则它可以旋转到四种支持的方向中的任意一种。
但是如果在开始景观,它并没有执行初始旋转,即使在发射后的设备旋转确实兑现了四种可能的旋转。
请注意,我已经实现所需的iOS 5和iOS 6的一切,并且该应用确实在所有iOS版本除了为其失败到处初始方向工作。
而且,请注意,我只有“纯香草”的局面,其中设备支持所有方向和应该工作“开箱即用”后(除了它不!)
#import "AppDelegate.h"
@interface TestUIVIew: UIView
@end
@implementation TestUIVIew
- (void) drawRect: (CGRect) rect {
CGContextRef context = ::UIGraphicsGetCurrentContext() ;
CGRect bounds = self.bounds ;
CGMutablePathRef p = ::CGPathCreateMutable() ;
CGFloat minx = ::CGRectGetMinX(bounds) ;
CGFloat miny = ::CGRectGetMinY(bounds) ;
CGFloat maxx = ::CGRectGetMaxX(bounds) ;
CGFloat maxy = ::CGRectGetMaxY(bounds) ;
CGPoint TL = (CGPoint) {minx, miny} ;
CGPoint BL = (CGPoint) {minx, maxy} ;
CGPoint TR = (CGPoint) {maxx, miny} ;
CGPoint BR = (CGPoint) {maxx, maxy} ;
::CGPathMoveToPoint (p, 0, TL.x, TL.y) ;
::CGPathAddLineToPoint (p, 0, BR.x, BR.y) ;
::CGPathMoveToPoint (p, 0, TR.x, TR.y) ;
::CGPathAddLineToPoint (p, 0, BL.x, BL.y) ;
::CGContextSetLineWidth(context, 5.0f) ;
::CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor) ;
::CGContextAddPath(context, p) ;
::CGContextStrokePath(context) ;
::CGPathRelease(p) ;
}
@end
@interface SimplestViewController : UIViewController
@end
@implementation SimplestViewController
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {
return YES ;
}
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll ;
}
- (BOOL) shouldAutorotate {
return YES ;
}
@end
@implementation AppDelegate
- (BOOL) application: (UIApplication *) application
didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController * vc = [SimplestViewController new] ;
vc.view = [TestUIVIew new] ;
self.window.rootViewController = vc ;
self.window.backgroundColor = [UIColor greenColor];
[self.window makeKeyAndVisible];
return YES;
}
@end
我已经尝试过模拟器5.0,5.1,6.0,& 6.1的所有变体,结果完全相同: 看来我只是没有得到任何旋转消息,或者如果我这样做,它是不受尊敬的。
所以,我主要添加了这个:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#define S(x) #x
#define str(x) case x: return @S(x)
static NSString * devO(UIDeviceOrientation o) {
switch (o) {
str(UIDeviceOrientationUnknown) ;
str(UIDeviceOrientationPortrait) ;
str(UIDeviceOrientationPortraitUpsideDown) ;
str(UIDeviceOrientationLandscapeLeft) ;
str(UIDeviceOrientationLandscapeRight) ;
str(UIDeviceOrientationFaceUp) ;
str(UIDeviceOrientationFaceDown) ;
default:
return [NSString stringWithFormat:@"??? UIDeviceOrientation<%08.8x> ???", o] ;
}
}
static NSString * intfO(UIInterfaceOrientation o) {
switch (o) {
str(UIInterfaceOrientationPortrait) ;
str(UIInterfaceOrientationPortraitUpsideDown) ;
str(UIInterfaceOrientationLandscapeLeft) ;
str(UIInterfaceOrientationLandscapeRight) ;
default:
return [NSString stringWithFormat:@"??? UIInterfaceOrientation<%08.8x> ???", o] ;
}
}
static void (^notifHandler)(NSNotification *) = ^(NSNotification *note) {
UIDeviceOrientation orientO = [UIDevice currentDevice].orientation ;
UIInterfaceOrientation orientI = [[UIApplication sharedApplication] statusBarOrientation];
::NSLog(@"! NOTE ! [device:%@--app:%@]\n--- %@ -> [%@] %@"
, devO(orientO)
, intfO(orientI)
, note.name
, note.object
, note.userInfo) ;
} ;
int main(int argc, char *argv[]) {
@autoreleasepool {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] ;
[[NSNotificationCenter defaultCenter] addObserverForName: nil
object: nil
queue: nil
usingBlock: notifHandler] ;
return UIApplicationMain(argc, argv, nil, ::NSStringFromClass([AppDelegate class]));
}
}
而这里的日志:
2013-04-26 17:43:06.429 AutoRotate[82160:1a03] ! NOTE ! [device:UIDeviceOrientationUnknown--app:??? UIInterfaceOrientation<00000000> ???]
--- kBKSDisplayServerDiedNotification -> [(null)] (null)
2013-04-26 17:43:06.489 AutoRotate[82160:2b03] ! NOTE ! [device:UIDeviceOrientationUnknown--app:??? UIInterfaceOrientation<00000000> ???]
--- NSWillBecomeMultiThreadedNotification -> [(null)] (null)
2013-04-26 17:43:06.523 AutoRotate[82160:c07] ! NOTE ! [device:UIDeviceOrientationUnknown--app:??? UIInterfaceOrientation<00000000> ???]
--- _UIWindowDidCreateWindowContextNotification -> [<UIStatusBarWindow: 0x9667540; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x96674a0>>] {
"_UIWindowContextIDKey" = "-1367435195";
}
[...]
2013-04-26 17:43:06.659 AutoRotate[82160:1a03] ! NOTE ! [device:UIDeviceOrientationPortrait--app:UIInterfaceOrientationPortrait]
--- kBKSHIDServerDiedNotification -> [(null)] (null)
2013-04-26 17:43:06.662 AutoRotate[82160:c07] ! NOTE ! [device:UIDeviceOrientationPortrait--app:UIInterfaceOrientationPortrait]
--- UIApplicationDidEndResumeAnimationNotification -> [<UIApplication: 0x7580b80>] (null)
2013-04-26 17:43:06.663 AutoRotate[82160:c07] ! NOTE ! [device:UIDeviceOrientationUnknown--app:UIInterfaceOrientationPortrait]
--- UIDeviceOrientationDidChangeNotification -> [<UIDevice: 0x7577d30>] {
UIDeviceOrientationRotateAnimatedUserInfoKey = 1;
}
通知的最后一行?
正如你可以看到一个旋转的通知确实发送...但有没有影响? 什么给?
困惑!
它在设备上工作!我知道一些模拟器的限制,...我想你只是发现了一个新的。谢谢! – verec 2013-04-26 20:49:58