2010-09-24 10 views
6

के साथ अभिविन्यास को कैसे प्रबंधित करें I iPad के लिए एक ऐप विकसित कर रहा हूं और मैं एकाधिक अभिविन्यास को संभालने का प्रयास करता हूं। मेरे ऐप में एक वेबव्यू और लोडिंग UIImageView है जो तब दिखाई देता है जब मेरा वेबव्यू सामग्री लोड कर रहा है।आईपैड एसडीके, UIImageView

यह UIImageView में एक पृष्ठभूमि छवि है जिसे मैंने इंटरफ़ेसबिल्डर में सेट किया है। जब मैं परिदृश्य में अभिविन्यास बदलता हूं, तो छवि काट दिया जाता है।

मैं यूआईएममेज व्यू को छवि-चित्रकार सेट करना चाहता हूं, जब आईपैड पोर्ट्रेट मोड और छवि-परिदृश्य में होता है जब यह लैंडस्केप मोड में होता है।

आपकी मदद और सलाह के लिए धन्यवाद!

स्क्रीनशॉट:

इंटरफ़ेस बिल्डर में, मैं स्क्रीन को भरने के ऑटो के लिए मेरे imageView का स्वत: आकार बदलना सेट:

alt text alt text

+0

वास्तव में क्या आप 'काट' मतलब है बाहर, बनाना चाहिए? एक तस्वीर सहायक होगी। – colithium

+0

मेरी छवि 768x1004 पोर्ट्रेट मोड में है। लैंडस्केप मोड में यह अभी भी 1024px की बजाय 768px चौड़ाई में है। मैं एक स्क्रीन पोस्ट करूंगा। – Salah

+0

यहां पोर्ट्रेट में स्क्रीनशॉट है: http://img202.imageshack.us/img202/9617/screenshot20100924at141.png और परिदृश्य: http://img832.imageshack.us/img832/9617/screenshot20100924at141.png – Salah

उत्तर

7

मैं एक समाधान मिल गया। मेरी ViewController में, मैं उन्मुखीकरण के परिवर्तन का पता लगाने के लिए एक विधि जोड़ सकते हैं और मैं आधार पर उपयुक्त छवि स्थापित कर दें तो आईपैड पोर्ट्रेट या लैंडस्केप में है:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){ 
    myImageView.image = [UIImage imageNamed:@"image-landscape.png"]; 
} else if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){ 
    myImageView.image = [UIImage imageNamed:@"image-portrait.png"]; 
} } 
+1

यह 'UIInterfaceOrientationIsLandscape' और' UIInterfaceOrientationIsPortrait' का उपयोग करने के लिए एक अच्छा मामला होगा। –

5

यह मुझे थोड़ी देर ले लिया इस अवधारणा को समझने के लिए। मैं एक ही छवि चित्र और परिदृश्य बनाना नहीं चाहता था। यहां कुंजी यह है कि CGAffineTransformMakeRotation उस मामले के लिए आपके UIImageView या किसी भी UIView की मूल स्थिति से घूमता है। यह मानता है कि आपकी पृष्ठभूमि छवि के प्रति अभिविन्यास है। जैसे आप अपने UIImageView को रखना चाहते हैं, जबकि अन्य ऑब्जेक्ट्स सामान्य अभिविन्यास परिवर्तन ईवेंट से व्यवहार करते हैं।

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
           duration:(NSTimeInterval)duration { 

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {   
     backgroundImage.transform = CGAffineTransformMakeRotation(M_PI/2); 
    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
     backgroundImage.transform = CGAffineTransformMakeRotation(-M_PI/2); 
    } 
    else { 
     backgroundImage.transform = CGAffineTransformMakeRotation(0.0); 
    } 
} 
1

जबकि सालाह अपने जवाब मेरे लिए ठीक लग रहा है मैं तुम यहाँ दोनों के सुधार कर सकते हैं विश्वास करते हैं:

  1. सेट इस समारोह के भीतर पृष्ठभूमि छवि:

    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    

    अवधि (NSTimeInterval) अवधि

    यदि आप didRotateFromInterfaceOrientation में परिवर्तन करते हैं तो आप पर समाप्त होने के बाद पृष्ठभूमि छवि को बदल देंगे और आईपैड घुमाएंगे और दो पृष्ठभूमि छवि से संक्रमण चिकनी नहीं होगा: आप स्पष्ट रूप से नई पृष्ठभूमि छवि पॉपअप देखेंगे घूर्णन के अंत में ।

    _myImageView.image = UIInterfaceOrientationIsLandscape (interfaceOrientation):

  2. myImageView.image मान सेट में सुधार? [UIImage imageNamed: @ "image-landscape.png"]: [UIImage imageNamed: @ "image-portrait.png"];

3

आप दृश्य autoresizing द्वारा उन्मुखीकरण संभाल कर सकते हैं।

UIImageView *imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background-image"]]; 

imageView.frame = self.view.bounds; 
imageView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight 
iimageView.contentMode = UIViewContentModeScaleAspectFill; 

[self.view addSubview:imageView]; 
[self.view sendSubviewToBack:imageView]; 

[imageView release]; 

यह आपकी समस्या का समाधान करेगा।

0

मैं वास्तव में डॉकचेंज के कोड में एक और शाखा जोड़ता हूं, जब आईपैड को पोर्ट्रेट के ऊपर घुमाया जाता है, तो यह पोर्ट्रेट दाएं-साइड-अप छवि का उपयोग करता है जो थोड़ा अजीब दिख सकता है। मैं कहा,

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
    { 
    imageBackgroundView.transform = CGAffineTransformMakeRotation(M_PI/2); 
    } 
else 
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
    imageBackgroundView.transform = CGAffineTransformMakeRotation(-M_PI/2); 
    } 
    else 
    if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
    imageBackgroundView.transform = CGAffineTransformMakeRotation(M_PI); 
    } 
    else 
     { 
     imageBackgroundView.transform = CGAffineTransformMakeRotation(0); 
     } 
0

यह दिलचस्प है प्रोग्रामर इस तरह के एक कठिन समय (इस मामले में सचमुच) बॉक्स के बाहर सोच है।

इसे आजमाएं (मैंने इसे स्वयं कैसे हल किया)।

  1. एक वर्ग छवि बनाएं।
  2. UIImageView की कमी सेट स्क्रीन (प्रमुख, अनुगामी, ऊपर, नीचे)
  3. पहलू को भरने के लिए मोड सेट में भरने (जो छवि विस्तार होगा, लेकिन इसकी पहलू अनुपात स्थिर रखने)
को

हो गया।

यहाँ मुख्य बिंदु है, ज़ाहिर है, कि तुम एक वर्ग छवि (जो है, जैसा कि मैंने ऊपर कहा बॉक्स ;-)