I have an ImageView with a png and I want to do this: when someone touch this imageview it's alpha change to 0.0, is it possible? (all without buttons)
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Yes, it is possible. For example you can do that with following steps:
in gesture handler set view's alpha to 0.0, you can do that with animation as well:
In recent Xcode, this is pretty easy. Go into the storyboard, in the object library search for "gesture", drag the one you want onto the image view. You can then treat the gesture object in the view hierarchy as the thing being tapped, i.e. control-drag from there to your view controller to connect the event handler.
Once there you can set the alpha as you like, although if you're trying to essentially remove the image view, you should set
imageView.hidden = true
/imageView.hidden = YES
instead, because that will stop it receiving events.you can use
UITapGestureRecognizer
added to theUIImageView
viaaddGestureRecognizer
snippets:
and
There are already lots of questions like this. Searching with google gave me the following:
touches event handler for UIImageView
UIImageView Touch Event
how can i detect the touch event of an UIImageView
The code in Swift
In my case I implemented the tap gesture for an image click
1 - Link the image with the ViewController, by drag and drop
2 - Instance the UITapGestureRecognizer in ViewDidLoad method:
3 - Create the method to do what do you want when the image clicked