• 思路

    图片预览,优先考虑基础控件UIImageView、UIButton

    图片预览中可能需设置不同的mode,优先考虑UIImageView

    typedef NS_ENUM(NSInteger, UIViewContentMode) {    UIViewContentModeScaleToFill,    UIViewContentModeScaleAspectFit,          UIViewContentModeScaleAspectFill,         UIViewContentModeRedraw,                 UIViewContentModeCenter,                  UIViewContentModeTop,    UIViewContentModeBottom,    UIViewContentModeLeft,    UIViewContentModeRight,    UIViewContentModeTopLeft,    UIViewContentModeTopRight,    UIViewContentModeBottomLeft,    UIViewContentModeBottomRight,}

    图片放大、缩小的思路:1. 手势+frame 2.scrollview的zoomScale

    很愉快的决定选择2,不要问为什么,因为我懒,能用系统提供的,坚决不折腾

  • 上菜

    • 设置页面属性
      @property (nonatomic, strong) UIScrollView *mScroll;@property (nonatomic, strong) UIImageView *imgInfo;
    • 界面初始化
      self.mScroll = [[UIScrollView alloc] initWithFrame:CGRectZero];self.mScroll.backgroundColor = [UIColor colorWithHexs:0x3f3f3f];self.mScroll.maximumZoomScale = 3.0;self.mScroll.minimumZoomScale = 1;self.mScroll.delegate = self;self.mScroll.showsVerticalScrollIndicator = NO;self.mScroll.showsHorizontalScrollIndicator = NO;[self.view addSubview:self.mScroll];[self.mScroll mas_makeConstraints:^(MASConstraintMaker *make) {make.edges.equalTo(self.preView);}];

    self.imgInfo = [[UIImageView alloc] initWithFrame:CGRectZero];
    self.imgInfo.clipsToBounds = YES;
    [self.imgInfo setUserInteractionEnabled:YES];
    self.imgInfo.backgroundColor = [UIColor colorWithHexs:0x3f3f3f];
    [self.mScroll addSubview:self.imgInfo];
    [self.imgInfo mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(self.mScroll);
    make.width.equalTo(self.mScroll);
    }];

    其中maximumZoomScale与minimumZoomScale表示可缩放程度- 顺带加个双击手势,比如双击可放大,再放大,再缩小

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandlerTwice)];
    tap.numberOfTapsRequired = 2;
    [self.imgInfo addGestureRecognizer:tap];

    - double click直接控制缩放
    • (void)tapHandlerTwice {
      if (self.mScroll.zoomScale < 2) {
      [self.mScroll setZoomScale:2];
      } else if (self.mScroll.zoomScale < 3) {
      [self.mScroll setZoomScale:3];
      } else {
      [self.mScroll setZoomScale:1];
      }
      }
    • UIScrollViewDelegate设置scrollview的Zooming View
      #pragma mark - UIScrollViewDelegate
    • (UIView )viewForZoomingInScrollView:(UIScrollView )scrollView {
      return self.imgInfo;
      }
  • Game Over
©著作权归作者所有:来自51CTO博客作者mb5fead26e428cc的原创作品,谢绝转载,否则将追究法律责任

更多相关文章

  1. 几款堪称神器的图片无损放大缩小工具!
  2. 在 React 中缩放、裁剪和缩放图像
  3. android官网demo之缩放view
  4. android中bitmap和drawable之间的转换
  5. android 两指缩放图片 event.getActionMasked() 方法的使用
  6. 百度地图 - Android所有Marker点显示在屏幕内
  7. android避免decodeResource图片时占用太大的内存
  8. android之基于Echart的图表
  9. [前端] 手机HTML页面制作经验

随机推荐

  1. 关于App.config的9篇文章推荐
  2. 关于处理指令的10篇文章推荐
  3. 有关XHTML的相关推荐10篇
  4. 关于原理及性能的详细介绍
  5. 总结关于百度新闻注意点
  6. 关于添加链接的详细介绍
  7. 有关WSD的详细介绍
  8. 关于XML开发的详细介绍
  9. OpenSearch的汇总分享
  10. 关于基本代码的10篇文章推荐