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