I set up two UI ImageViews on the storyboard, each with the same image.
I set the tag to 1 and 2 respectively.
@IBOutlet weak variv2:UIImageView!
@IBOutlet weak variv:UIImageView!
override func viewDidLoad(){
super.viewDidLoad()
varimg = UIImage(named: "paint2.png")
iv.image=img
iv2.image=img
}
override functouchesBegan(touches:NSSet, withEvent:UIEvent) {
var touch = touches.anyObject() as UITouch
println(touch.view.tag)
switch(touch.view.tag){
case1:
break
case2:
break
default:
break
}
}
As a result, 1,2 will be output to LOG when UIImageView is tapped, and 0 will be output when pressed otherwise.
What I want to do is to tap UIImageView and move to the next screen, and I want to release a large image of the tapped image.
It's like a detail screen.
Please.
There are several techniques, but UIGestureRecognizer, UITapGesConsider a pattern that utilizes the textureRecognizer.
override func viewDidLoad(){
super.viewDidLoad()
let img = UIImage(named: "paint2.png")
iv.image=img
iv2.image=img
let gesture=UITapGestureRecognizer(target:self, action "didClickImageView:")
iv.addGestureRecognizer(gesture)
iv2.addGestureRecognizer(gesture)
}
func didClickImageView (recognizer: UIGestureRecognizer) {
iflet imageView=recognizer.view as?UIImageView{
let image=imageView.image
let nextViewController=/**The following UIViewController instances*/
nextViewController.image=iamge
/** Transition to netViewController*/
}
}
© 2024 OneMinuteCode. All rights reserved.