2011-01-21 16 views
12

मेरे ऐप में मैं डिवाइस रोटेशन (ओरिएंटेशन चेंज) के मामले में सीसीएससीन माइस्सेन में कुछ विधि कॉल करना चाहता हूं। मैंने ऑटोरोटेशन को अक्षम कर दिया (क्योंकि मैं ऐसा नहीं करना चाहता)।डिवाइस अभिविन्यास (इंटरफ़ेस अभिविन्यास नहीं) की स्थिति पर स्वयं की सदस्यता कैसे लें?

समस्या यह है: मैं अपने डिवाइस अभिविन्यास के आधार पर दृश्य में गुरुत्वाकर्षण को बदलना चाहता हूं। मेरे कोड:

-(void) onEnter 
{ 
    [super onEnter]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification_OrientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification_OrientationDidChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; 
} 
-(void) onExit 
{ 
    //[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; 
    //[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; 
} 
-(void)notification_OrientationWillChange:(NSNotification*)n 
{ 
    orientation = (UIInterfaceOrientation)[[n.userInfo objectForKey:UIApplicationStatusBarOrientationUserInfoKey] intValue]; 
} 
-(void)notification_OrientationDidChange:(NSNotification*)n 
{ 
    if (orientation == UIInterfaceOrientationLandscapeLeft) { 
     b2Vec2 gravity(0, -10); 
     world->SetGravity(gravity); 
    } 
    if (orientation == UIInterfaceOrientationLandscapeRight) { 
     b2Vec2 gravity(0, 10); 
     world->SetGravity(gravity); 
    } 
} 

लेकिन इस मामले में मैं केवल autorotation के मामले सक्षम में सूचनाएं प्राप्त कर सकते हैं (यदि यह विकलांग, उपकरण वास्तव में है यह स्थिति पट्टी ओरिएंटेशन बदलने नहीं है) क्या आप मेरी मदद कर सकते हैं।?

उत्तर

28
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(orientationChanged:) 
              name:@"UIDeviceOrientationDidChangeNotification" 
              object:nil]; 



- (void)orientationChanged:(NSNotification *)notification{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

    //do stuff 
    NSLog(@"Orientation changed");   
} 

आपको डिवाइस अभिविन्यास को स्टेटस बार नहीं देखना चाहिए।

typedef enum { 
     UIDeviceOrientationUnknown, 
     UIDeviceOrientationPortrait,   // Device oriented vertically, home button on the bottom 
     UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top 
     UIDeviceOrientationLandscapeLeft,  // Device oriented horizontally, home button on the right 
     UIDeviceOrientationLandscapeRight,  // Device oriented horizontally, home button on the left 
     UIDeviceOrientationFaceUp,    // Device oriented flat, face up 
     UIDeviceOrientationFaceDown    // Device oriented flat, face down 
    } UIDeviceOrientation; 
+1

अनुपलब्ध '' '। – Macarse

+0

डिवाइस अभिविन्यास का उपयोग करना बहुत संवेदनशील है, यह 45 डिग्री परिदृश्य पर पोर्ट्रेट में बदल जाएगा। – danfordham

+0

यही कारण है कि इसे ** डिवाइस अभिविन्यास ** कहा जाता है और नहीं ** इंटरफ़ेस अभिविन्यास **। एक मोबाइल डिवाइस इसके अभिविन्यास को बहुत ही बार बदल सकता है जिस तरह से इसे पकड़ता है। इंटरफ़ेस अभिविन्यास में रूचि रखने वाले लोगों को UIViewController की संपत्ति का उपयोग करना चाहिए :) – nacho4d

संबंधित मुद्दे