2010-10-06 14 views
6

मैं एक छवि है कि मैं एक छवि दृश्य में लोड और बड़े पैमाने की तरह एक aspectFill को minimumZoomScale, साथ ही zoomScale सेट है कि मैं गणना करना चाहते हैं इस प्रकार है:एक UIScrollView के minimumZoomScale गिना जा रहा है

// configure the map image scroll view 
iImageSize = CGSizeMake(iImageView.bounds.size.width, iImageView.bounds.size.height); 
iScrollView.minimumZoomScale = iScrollView.bounds.size.height/iImageSize.height; 
iScrollView.maximumZoomScale = 2; 
iScrollView.zoomScale = iScrollView.minimumZoomScale; 
iScrollView.contentOffset = CGPointMake(0, 0); 
iScrollView.clipsToBounds = YES; 

iScrollView आकार 450 x 320px है और iImageSize 1600 x 1960px है।

हाथ से न्यूनतम ज़ूमस्केल गणित करना: 450/1 9 60 = 0.22959184। सिस्टम इसके बजाय 0.234693885 निर्धारित करता है (???)।

लेकिन खिड़की 450px अंतरिक्ष में फिट करने के लिए, दोनों आंकड़े काम नहीं करते (!!!)। मैंने मैन्युअल रूप से कोशिश की और पाया कि 0.207 सही संख्या है (जो 2174 xp की छवि ऊंचाई या वैकल्पिक रूप से 406px की UIScrollView ऊंचाई का अनुवाद करेगा)।

जानकारी के लिए: UIScrollView स्क्रीन 450px 480px गुणित शून्य से स्थिति पट्टी ऊंचाई (10), शून्य से UITabBar ऊंचाई (20)

इस दुर्व्यवहार पर कोई सुराग है, अर्थात्?

+0

मुझे लगता है कि का सामना किया है और साथ ही:

कोड यह रहा। मैंने न्यूनतम मूल्य को कुछ मान पर सेट किया है, फिर यह किसी बिंदु पर स्वतः लोड हो जाता है। हालांकि समायोजन कम या ज्यादा अनजान है, मैंने अभी इसे छोड़ दिया है, और इसके बाद ही इस लाइन को scrollview.zoomScale = scrollview.minimumZoomScale जोड़ दिया है; बस यह सुनिश्चित करने के लिए कि सब कुछ सिंक हो गया है। – Altealice

उत्तर

0

साधारण ज़ूम इन/आउट के लिए मैं आमतौर पर नीचे कोड का उपयोग करता हूं। minimalZoomScale = 1 वर्तमान छवि आकार में प्रारंभिक ज़ूम सेट करता है। मैंने maxZoomScale = 10 दिया है जिसे छवि आकार और कंटेनर फ्रेम आकार के वास्तविक अनुपात से गणना की जा सकती है।

[scrollView addSubview: iImageView]; 
    scrollView.contentSize = iImageView.frame.size; 
    scrollView.minimumZoomScale = 1.0; 
    scrollView.maximumZoomScale = 10; 
    [iImageView setFrame:CGRectMake(0, 0, 450, 320)]; 
[scrollView scrollRectToVisible:iImageView.frame animated:YES]; 
0

सुनिश्चित नहीं है कि आपको अभी भी यह समस्या है, लेकिन मेरे लिए, पैमाने बिल्कुल विपरीत है। मेरे लिए minimumZoomScale = 1 और मुझे maximumZoomScale की गणना करना है।

[self.imageView setImage:image]; 
// Makes the content size the same size as the imageView size. 
// Since the image size and the scroll view size should be the same, the scroll view shouldn't scroll, only bounce. 
self.scrollView.contentSize = self.imageView.frame.size; 

// despite what tutorials say, the scale actually goes from one (image sized to fit screen) to max (image at actual resolution) 
CGRect scrollViewFrame = self.scrollView.frame; 
CGFloat minScale = 1; 
// max is calculated by finding the max ratio factor of the image size to the scroll view size (which will change based on the device) 
CGFloat scaleWidth = image.size.width/scrollViewFrame.size.width; 
CGFloat scaleHeight = image.size.height/scrollViewFrame.size.height; 
self.scrollView.maximumZoomScale = MAX(scaleWidth, scaleHeight); 
self.scrollView.minimumZoomScale = minScale; 
// ensure we are zoomed out fully 
self.scrollView.zoomScale = minScale; 
संबंधित मुद्दे