【发布时间】:2016-12-09 02:17:15
【问题描述】:
我是 Swift 新手,我正在寻找一种通过双击将图像移动到其他视图控制器的方法。
我把我的图片做成了滚动视图,所以我可以滑动来查看它。
这是我的代码。
class Quotes: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scroll: UIScrollView!
let imageview = ["quotes1","quotes2","quotes3","quotes4"]
var imagine = UIImageView()
override func viewDidLoad() {
let tap = UITapGestureRecognizer(target: self, action: #selector(doubletap))
tap.numberOfTapsRequired = 2
view.addGestureRecognizer(tap)
self.navigationController?.setNavigationBarHidden(true, animated: true)
quotesimageload()
}
func quotesimageload() {
for index in 0 ... imageview.count - 1
{
imagine = UIImageView (frame:CGRect(x: self.scroll.frame.width * CGFloat(index), y: 0 , width: self.scroll.frame.width, height: self.scroll.frame.height))
imagine.image = UIImage(named : imageview[index])
imagine.tag = index
imagine.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.scroll.addSubview(imagine)
}
self.scroll.contentSize = CGSize(width: self.scroll.frame.width * CGFloat(imageview.count), height: self.scroll.frame.height)
}
func doubletap(){
let view = self.storyboard?.instantiateViewController(withIdentifier: "pinch")
self.navigationController?.pushViewController(view!, animated: true)
}
}
【问题讨论】:
标签: ios swift uiscrollview uiimageview uitapgesturerecognizer