iOS show UIImage full screen with zooming (pinch and double tap) enabled(iOS 显示 UIImage 全屏并启用缩放(捏合和双击))
问题描述
我有一个使用 UIImagePickerController
从相机捕获的 UIImage
.
I have an UIImage
captured from the camera with UIImagePickerController
.
现在,在用户单击它后,我希望它显示全屏,并能够使用捏合手势和双击手势来放大和缩小特定区域.换句话说,我想模仿ios默认图片浏览器的功能.
Now after the user clicks on it, I'd like it to show full screen and be able to to zoom it in and out using pinch gestures and also the double tap gesture to zoom in a particular area. In other words, I'd like to emulate what the ios's default image browser does.
我在 UIImageView
中显示捕获的图像:
I display the captured image in an UIImageView
with:
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
这会使图像全屏显示.但是我如何实现缩放.我需要使用手势识别器从头开始吗?或者也许有一个默认的图像显示视图,其中包含我不知道的所有实现?
which makes the image go full screen. But how do I implement zooming. Do I need to do it from scratch using gesture recognizers? Or maybe there's a default image display view with all that implemented I am not aware of?
推荐答案
我已经为我的一个应用创建了这个效果,不要忘记设置你的滚动视图的委托.
i have create this effect for one of my app, dont forget to set delegate of your scrollview.
.h 文件的代码
#import <UIKit/UIKit.h>
@interface ImageViewerController : UIViewController<UIScrollViewDelegate>
// The scroll view used for zooming.
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
// The image view that displays the image.
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
// The image that will be shown.
@property (strong, nonatomic) NSString *imageUrlString;
@end
.m 的代码
#import "ImageViewerController.h"
@interface HNImageViewerController ()
- (IBAction)handleSingleTap:(UIButton*)tapGestureRecognizer;
@end
@implementation ImageViewerController
- (void)viewDidLoad {
[super viewDidLoad];
[self.imageView setImage:[UIImage imageNamed:@"placeholder-image"]];
self.scrollView.delegate=self;
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
#pragma mark - UIScrollViewDelegate methods
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return self.imageView;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (self.scrollView.zoomScale == self.scrollView.minimumZoomScale) {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
#pragma mark - Private methods
- (IBAction)handleSingleTap:(UIButton *)tapGestureRecognizer {
[self dismissViewControllerAnimated:YES completion:nil];
}
这篇关于iOS 显示 UIImage 全屏并启用缩放(捏合和双击)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 显示 UIImage 全屏并启用缩放(捏合和双击)
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01