//
// ViewController.swift
// SwiftAppLab
//
// Created by Bear on 2017/2/4.
// Copyright © 2017年 BeargerHunter. All rights reserved.
//
import UIKit
import Foundation
import SnapKit
class ViewController: UIViewController{
lazy var scrollView = { () -> UIScrollView in
let temp = UIScrollView()
temp.showsVerticalScrollIndicator = false
temp.showsHorizontalScrollIndicator = false
temp.maximumZoomScale = 3
return temp
}()
lazy var imageView = { () -> UIImageView in
let imageView = UIImageView(image: #imageLiteral(resourceName: "test1.jpg"))
imageView.isUserInteractionEnabled = true
return imageView
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = UIColor.white
self.title = "Bear"
scrollView.frame = self.view.frame
self.view.addSubview(scrollView)
scrollView.backgroundColor = UIColor.blue
scrollView.delegate = self
scrollView.addSubview(imageView)
let doubleTapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(handleTapGesture(_:)))
doubleTapGestureRecognizer.numberOfTapsRequired = 2
imageView.addGestureRecognizer(doubleTapGestureRecognizer)
}
func handleTapGesture(_ gesture:UIGestureRecognizer) {
if scrollView.zoomScale > 1.0 {
scrollView.setZoomScale(1.0, animated: true)
}else{
let touchPoint = gesture.location(in: imageView)
let newZoomScale = scrollView.maximumZoomScale
let xsize = self.view.frame.width/newZoomScale
let ysize = self.view.frame.height/newZoomScale
scrollView.zoom(to: CGRect.init(x:touchPoint.x - xsize/2, y:touchPoint.y - ysize/2, width:xsize, height:ysize), animated: true)
}
}
}
//Important:查看对应文档~
extension ViewController :UIScrollViewDelegate
{
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return self.imageView
}
}
UIScrollView双击放大
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- //// ImageVC.h// MovieCrowdfunding//// Created by Sun-Mac...
- 我这里是封装的一个单独的UIScrollView,用在制作相册的时候使用。 双指缩放代码 双击定点放大代码 这样就...
- 一.前言 今天我们就来实现简书的导航栏图片随着UIScrollView的滚动来改变的效果,简书的效果图如下: 二....
- 因为个人公司项目特殊需求,网上一些比较好的三方图片浏览只好排除.(个人推荐:PYPhotoBrowser,附带Gi...