//
// GA_ImageView.swift
// GA_BrowseImage
//
// Created by houjianan on 2016/12/5.
// Copyright © 2016年 houjianan. All rights reserved.
//
import UIKit
class GA_ImageView: UIView {
typealias TouchEndedHandler = () -> ()
var touchEndedHandler: TouchEndedHandler!
lazy var myImageView: UIImageView = {
let i = UIImageView()
i.frame = self.bounds
i.image = UIImage(named: "123.png")
self.addSubview(i)
return i
}()
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
convenience init(frame: CGRect, handler: @escaping TouchEndedHandler) {
self.init(frame: frame)
touchEndedHandler = handler
print(myImageView)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
print(touches)
let touch = touches.first
let view = touch?.view
print(view!)
let location = touch?.location(in: view)
print(location!)
let x: CGFloat = (location?.x)!
let y: CGFloat = (location?.y)!
let v = UIView(frame: CGRect(x: x, y: y, width: 0, height: 0))
v.backgroundColor = UIColor.orange
self.addSubview(v)
let superView = self.superview!
UIView.animate(withDuration: 0.4, animations: {
v.frame = CGRect(x: -self.frame.origin.x, y: -self.frame.origin.y, width: superView.frame.size.width, height: superView.frame.size.height)
}, completion: {
bo in
UIView.animate(withDuration: 0.3, animations: {
v.alpha = 0
}, completion: { (bo) in
v.removeFromSuperview()
self.touchEndedHandler()
})
})
}
}
swift - 一个从点击位置变大的view
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 下面选了最近十年里,十位名人所做的毕业演讲。那么多的故事与经历,其实只想告诉你一件事: 面对迷茫和不确定的未来,我...