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 全屏并启用缩放(捏合和双击)
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01