2010-12-07 10 views
5

मेरी स्प्लैश स्क्रीन काम कर रही है, लेकिन मेरा ऐप लैंडस्केप मोड पर काम करता है, और स्पलैश स्क्रीन डिफ़ॉल्ट पोर्ट्रेट मोड में दिखाती है।मैं आईओएस पर कस्टम स्पलैश स्क्रीन कैसे घुमा सकता हूं?

मैं ऐप कैसे शुरू कर सकता हूं ताकि स्प्लैश स्क्रीन मेरे ऐप जैसे लैंडस्केप मोड के बीच घूमती है?

मैं निम्नलिखित कोड का उपयोग कर रहा:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Overriden to allow any orientation. 
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
    interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    return YES; 
else { 
    return NO; } 
} 

और स्प्लैश स्क्रीन

-(void)displayScreen { 
UIViewController *displayViewController=[[UIViewController alloc] init]; 
displayViewController.view = displaySplashScreen; 
[self presentModalViewController:displayViewController animated:NO]; 
[self performSelector:@selector(removeScreen) withObject:nil afterDelay:3.0]; 
} 
-(void)removeScreen 
{ [[self modalViewController] dismissModalViewControllerAnimated:YES]; 
} 

के लिए लेकिन यह कैसे मैं डिस्प्ले स्क्रीन के अंदर घुमाने रख सकते हैं?

+0

इस पोस्ट में वास्तव में एक्सकोड के साथ कुछ भी नहीं है। इसलिए, मैंने आपके शीर्षक से वह शब्द हटा दिया है। –

+0

ने आईफोन और आईपैड टैग जोड़े, क्योंकि बहुत से लोगों के पास यह एफएवी है और आपको बेहतर दृश्य संख्या मिल जाएगी –

उत्तर

3

@zoul - इस समाधान प्यार अब तक। हालांकि, अगर उस दृश्य में कोई सबव्यूव है - वे दिखाई नहीं देते हैं। कोई विचार?

अद्यतन:

-startupImageWithOrientation:नहीं self.view में बनाया UIView करने के लिए एक subview जोड़कर इस समस्या का समाधान हो।

- (UIView *)startupImageWithOrientation:(UIInterfaceOrientation)io{ 
    UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"Default-%@.png", UIInterfaceOrientationName(io)]]; 
    UIView *aView = [[UIImageView alloc] initWithImage:img]; 
    [aView setFrame:[[UIScreen mainScreen] applicationFrame]]; 

    // define the version number label 
    self.versionNumberLabel_iPadSplashScreen.text = [NSString stringWithFormat:@"Version %@", 
                      [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]; 

    [aView addSubview:self.versionNumberLabel_iPadSplashScreen]; 

    return [aView autorelease]; 
} 
4

आह। यदि आप अपनी खुद की स्प्लैश स्क्रीन प्रदर्शित करना चाहते हैं, तो आपको इसके लिए एक विशेष दृश्य नियंत्रक बनाना चाहिए, जिसे आपने पहले ही किया है। मुझे लगता है कि आप autorotation क्वेरी कोड को आसान बनाने में कर सकते हैं:

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) foo 
{ 
    return YES; // all interface orientations supported 
} 

अब आप अलग झुकाव के लिए छप स्क्रीन के बारे में सोचना। क्या आपके पास परिदृश्य और चित्र के लिए एक अलग स्पलैश छवि है?

- (UIView*) startupImageWithOrientation: (UIInterfaceOrientation) io 
{ 
    UIImage *img = [UIImage imageNamed:[NSString 
     stringWithFormat:@"Default-%@.png", UIInterfaceOrientationName(io)]]; 
    UIView *view = [[UIImageView alloc] initWithImage:img]; 
    [view setFrame:[[UIScreen mainScreen] applicationFrame]]; 
    return [view autorelease]; 
} 

- (void) loadView 
{ 
    self.view = [self startupImageWithOrientation:self.interfaceOrientation]; 
} 

- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) io 
    duration: (NSTimeInterval) duration 
{ 
    self.view = [self startupImageWithOrientation:io]; 
    self.view.transform = CGAffineTransformFromUIOrientation(io); 
} 

दो उपयोगिता कार्यों कहा जाता है, तो आपको एक अलग फाइल में इन सामान कर सकते हैं:

NSString *UIInterfaceOrientationName(UIInterfaceOrientation io) 
{ 
    return UIInterfaceOrientationIsPortrait(io) ? @"Portrait" : @"Landscape"; 
} 

CGAffineTransform CGAffineTransformFromUIOrientation(UIInterfaceOrientation io) 
{ 
    assert(io <= 4); 
    // unknown, portrait, portrait u/d, landscape L, landscape R 
    static float angles[] = {0, 0, M_PI, M_PI/2, -M_PI/2}; 
    return CGAffineTransformMakeRotation(angles[io]); 
} 

यह थोड़ा गंदा है, मुझे कोई दिलचस्पी होगी हाँ, तो आप कुछ इस तरह कर सकते हैं सरल समाधान में खुद।

1

यदि आपके पास उन्मुखताएं लॉक हैं तो आपके defult.png का संकल्प आपके ऐप्स अभिविन्यास को प्रभावित कर सकता है।

उदाहरण के लिए यदि 1024x768 स्पलैश छवि का उपयोग किया जाता है और प्रारंभिक दृश्य अभिविन्यास ताले के माध्यम से पोर्ट्रेट देखने का समर्थन नहीं करता है तो यह विज़ुअल UI ऑब्जेक्ट्स को स्क्रीन से प्रदर्शित होने का कारण बन सकता है (विशेष रूप से जब एनीमेशन शामिल होता है) क्योंकि दृश्य प्रयास और उपस्थित होगा डिवाइस पोर्ट्रेट कॉन्फ़िगरेशन में स्वयं भी भले ही डिवाइस परिदृश्य में हो।

आम तौर पर, 1024x768 छवियां चित्र को दर्शाती हैं जबकि 768x1024 छवियां परिदृश्य दर्शाती हैं।

यदि यह पर्याप्त नहीं है, या आप प्रारंभिक डिफ़ॉल्ट छवि से एक लॉगिन स्क्रीन में सहजता से जाने की इच्छा रखते हैं, तो आप स्पलैश को 'जारी रखने' के लिए व्यू कंट्रोलर का उपयोग कर सकते हैं।

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Overriden to allow any orientation. 

switch ([[UIDevice currentDevice] orientation]) 
{ 
    case UIInterfaceOrientationLandscapeRight: 
    splashImage.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Default"] ofType:@"png"]]; 
    break; 
    case UIInterfaceOrientationPortrait: 
    splashImage.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Default"] ofType:@"png"]]; 
    break; 
    default: 
    splashImage.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Default2"] ofType:@"png"]]; 
    break; 
} 

    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 

के विन्यास:

लोड सभी सामान्य विंडो में viewControllers, तो अपने 'छप' ViewController में तो अपने splashController उपयोग में shouldAutorotateToInterfaceOrientation विधि (एक ImageViewController पर) सही छवि स्थापित करने के लिए डाल दिया जिन छवियों का मैंने उपयोग किया है वे आपके अनुरूप नहीं हो सकते हैं, इसलिए कुछ प्रयोगों की आवश्यकता हो सकती है।

0
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait) 
    { 
     // take action here , when phone is "Portrait" 

    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
    { 
     action 4 LandscapeLeft 

    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     //PortraitUpsideDown 

    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     //LandscapeRight 

    } 

ध्यान दें कि आप हाँ लौट जाना विधि shouldAutorotateToInterfaceOrientation: