IOS:在滚动视图中添加图像视图以进行缩放
- 作者: 丨至高无上丨
- 来源: 51数据库
- 2022-10-20
问题描述
我想用 UIImage 设置 UIImageView 并将这个 imageview 放在 UIScrollView 中以获得这个图像的缩放;我希望这个 UIImageView 和 UIScrollView 适合视图中心的矩形...有可能吗?
解决方案
- 将您的视图控制器设置为 <UIScrollViewDelegate>
- 将 UIScrollView 绘制为视图中心矩形所需的大小.将检查器中的最大缩放设置为大于 1 的值.例如 4 或 10.
- 右键单击滚动视图并将代理连接到您的视图控制器.
- 在 UIScrollView 中绘制您的 UIImageView 并使用您想要的任何图像进行设置.使其与 UIScrollView 的大小相同.
- Ctrl + 将 UIImageView 拖动到 View 控制器的 .h 中,为 UIImageView 创建一个 IBOutletcode>,把它称为 imageView 之类的聪明东西.
添加此代码:
<块引用>-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView{返回self.imageView;}运行应用程序并捏合和平移,直到心满意足.
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 the UIScrollView and set it up with whatever image you want. Make it the same size as the UIScrollView.
- Ctrl + drag form you UIImageView to the .h of your View controller to create an IBOutlet for the UIImageView, call it something clever like imageView.
Add this code:
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.imageView; }Run the app and pinch and pan til your heart's content.
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
