2010-11-20 9 views
5

के घूर्णन के बाद UIScrollView में ऑफ़सेट करें में मेरे पास UIImageView है और मुझे contentOffset संपत्ति के साथ कुछ परेशानी है। ऐप्पल के संदर्भ से, इसे परिभाषित किया गया है:सामग्री आईफोन

सामग्री ऑफसेट: जिस बिंदु पर सामग्री दृश्य की उत्पत्ति स्क्रॉल व्यू की उत्पत्ति से ऑफसेट होती है।

उदाहरण के लिए, यदि छवि तो नीचे के रूप में स्क्रीन के ऊपरी बाएँ कोने पर है contentOffset होगा (0,0):

_________ 
    |IMG | 
    |IMG | 
    |  | 
    |  | 
    |  | 
    |  | 
    --------- 

डिवाइस रोटेशन के लिए मैं निम्नलिखित सेटिंग है:

scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | 
     UIViewAutoresizingFlexibleHeight); 

imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | 
     UIViewAutoresizingFlexibleHeight); 

imageView.contentMode = UIViewContentModeCenter; 
    scrollView.contentMode = UIViewContentModeCenter; 

यह सब कुछ स्क्रीन के केंद्र के चारों ओर घूमने कर देगा। स्क्रीन घुमाने के बाद, फिर स्क्रीन तो इस तरह दिखेगा:

______________ 
    |  IMG | 
    |  IMG | 
    |   | 
    -------------- 

मेरे समस्या यह है कि अगर मैं अब contentOffset की पढ़ते हैं, यह अभी भी है (0,0) है। (यदि मैं यूआईएममेज को लैंडस्केप मोड में ले जाता हूं, तो contentOffset का मान अपडेट किया गया है, लेकिन यह गलत उत्पत्ति के संबंध में गणना की जाती है।)

ऊपरी बाईं ओर यूआईएममेज के निर्देशांक की गणना करने का कोई तरीका है स्क्रीन के कोने। contentOffset केवल इस मान को वापस करने लगता है जब स्क्रीन दृश्य के प्रारंभिक अभिविन्यास में है।

मैंने self.view.transform और scrollView.transform पढ़ने की कोशिश की है, लेकिन वे हमेशा पहचान हैं।

उत्तर

3

यहाँ एक तरीका यह है है: scrollview के लिए

scrollView.autoresizingMask =(UIViewAutoresizingFlexibleWidth 
            | UIViewAutoresizingFlexibleHeight); 

scrollView.contentMode = UIViewContentModeTopRight; 

UIViewContentModeTopRight मोड सेट ऊपरी बाएँ कोने रखने में समन्वय (0,0) भले ही रोटेशन व्यवहार सही नहीं है जाएगा। एक ही रोटेशन व्यवहार प्राप्त करने के लिए UIViewContentModeCenter में के रूप में willAnimateRotationToInterfaceOrientation में जोड़ने

scrollView.contentOffset = fix(sv.contentOffset, currentOrientation, goalOrientation); 

fix समारोह

CGPoint fix(CGPoint offset, UIInterfaceOrientation currentOrientation, UIInterfaceOrientation goalOrientation) { 

CGFloat xx = offset.x; 
CGFloat yy = offset.y; 

CGPoint result; 

if (UIInterfaceOrientationIsLandscape(currentOrientation)) { 

    if (UIInterfaceOrientationIsLandscape(goalOrientation)) { 
     // landscape -> landscape 
     result = CGPointMake(xx, yy); 
    } else { 
     // landscape -> portrait 
     result = CGPointMake(xx+80, yy-80); 
    } 
} else { 
    if (UIInterfaceOrientationIsLandscape(goalOrientation)) { 
     // portrait -> landscape 
     result = CGPointMake(xx-80, yy+80); 
    } else { 
     // portrait -> portrait 
     result = CGPointMake(xx, yy); 
    } 
} 
return result; 
} 

ऊपर कोड scrollview कर देगा स्क्रीन के केंद्र के चारों ओर घूमने और यह भी सुनिश्चित करना है कि ऊपरी बाएँ Corder हमेशा से रहे हैं निर्देशांक (0,0) है।