本文介紹了IOS:在滾動視圖中添加圖像視圖以進(jìn)行縮放的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我想用 UIImage
設(shè)置 UIImageView 并將這個 imageview 放在 UIScrollView
中以獲得這個圖像的縮放;我希望這個 UIImageView
和 UIScrollView
適合視圖中心的矩形...有可能嗎?
解決方案
- 將您的視圖控制器設(shè)置為
<UIScrollViewDelegate>
- 將
UIScrollView
繪制為視圖中心矩形所需的大小.將檢查器中的最大縮放設(shè)置為大于 1 的值.例如 4 或 10. - 右鍵單擊滾動視圖并將代理連接到您的視圖控制器.
- 在
UIScrollView
中繪制您的UIImageView
并使用您想要的任何圖像進(jìn)行設(shè)置.使其與UIScrollView
的大小相同. - Ctrl + 將
UIImageView
拖動到 View 控制器的.h
中,為UIImageView
創(chuàng)建一個IBOutlet
code>,把它稱為imageView
之類的聰明東西. 添加此代碼:
<塊引用>-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView{返回self.imageView;}
運(yùn)行應(yīng)用程序并捏合和平移,直到心滿意足.
I want to set a UIImageView with a UIImage
and put this imageview inside a UIScrollView
to obtain a zoom of this image;
and I want this UIImageView
and UIScrollView
to fit in the rect at the center of the view...is it possible?
解決方案
- Set your view controller up as a
<UIScrollViewDelegate>
- Draw your
UIScrollView
the size you want for the rectangle at the center of the view. Set the max zoom in the inspector to something bigger than 1. Like 4 or 10. - Right click on the scroll view and connect the delegate to your view controller.
- Draw your
UIImageView
in theUIScrollView
and set it up with whatever image you want. Make it the same size as theUIScrollView
. - Ctrl + drag form you
UIImageView
to the.h
of your View controller to create anIBOutlet
for theUIImageView
, call it something clever likeimageView
. Add this code:
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.imageView; }
Run the app and pinch and pan til your heart's content.
這篇關(guān)于IOS:在滾動視圖中添加圖像視圖以進(jìn)行縮放的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!