2013-04-26 4 views
1

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, 새 프로젝트, 빈 응용 프로그램을 사용하고 있습니다.

결과적으로 응용 프로그램이 세로 방향으로 시작된 경우 지원되는 4 개의 방향 중 하나로 회전 할 수 있습니다.

에 가로, 을 시작하지만 경우가 하지 초기 회전을 수행 않습니다 출시 후 장치를 회전하면 네 가지 회전을 존중하지 않더라도.

, 나는에서 iOS 5 및 iOS 6에 필요한 모든 것을 구현 한 점에 유의주세요 응용 프로그램 모든 아이폰 OS 버전의 모든 곳에서 실패 초기 방향에 대한 제외 에서 작업을 수행하는 것이.

또한, 난 단지 장치가 모든 방향으로을 지원하고이 "상자 밖으로"일을해야한다 "평범한"상황 후에임을 유의하시기 바랍니다 (그렇지 않은 것을 제외!)

#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; 
} 

주의 마지막 줄?

Here's a screen shot

당신이 참으로 전송되는 회전 알림을 볼 수 있듯이

...하지만이 적용되지 않습니다? 무엇을 제공합니까?

수수께끼!

답변

1

시뮬레이터 대신 실제 장치로 시도하십시오.

+0

기기에서 작동합니다! 시뮬레이터의 제한점 중 일부를 알고 있었는데, 당신이 방금 새로운 것을 발견했다고 생각합니다. 감사! – verec