Detecting tap on the UIImageViews added to UIScrollView - iphone

I am developing an application in iPhone which has a UIScrollView to which I have added an array of image views (like thumbnails,using loop). The User can scroll either way horizontally and select a particular image. The image on which the user taps has to displayed in a separate UIImageView. I have achieved till the detection of tap on the UIScrollView.But I dunno how to determine which image received the tap so that I can show a preview of that in the UIImageView. How to achieve that ? Any help on this would be appreciated ! Thanks in advance.

When I meet UIScrollView and UIImageView.I always use UIButton instead of UIImageView and use setTag to get which button is pressed.

How do you capture the tap? If it's done by UIGestureRecognizer then you should not forget that a gesturerecognizer can be added only to one object. So you can not catch taps on multiple objects via just one gesturerecognizer. So, in your loop where you create those imageviews also create a UITapGestureRecognizer bound the that imageview.

Related

Add item to UIView without blocking recognisers

How do I add a UIButton, UIImage, UILabel etc. without blocking any function the widget behind is set to call?
For example, I may have a UIButton, and on top of it, a UIImage (which will be smaller than the button, you would still be able to see and tap the button). How do I make it so when the UIImage is tapped the button behind's function is triggered? Note: I don't want to programme the image to have the same function as the button, nor do I want to simply add an image to the button. I want it to be on top.
I'm using Swift 5, Xcode 10.2, and MacBook Pro.
Thanks!
I would have one main UIView which would include your UIButton as well as UIImageView and then I would just add UITapGestureRecognizer to the main view to handle when view gets tapped.

Two finger swipe on a UITableView

I am using a UITableView in my application to show a set of images under each section in a UITableView.I have a requirement which makes the UITableView to scroll to next section if the swipe is done with two fingers.
Can some one help me in making the UITableView respond to two finger swipe.I tried by assigning a swipe gesture with number of touches assigned to two but the table responds to normal traditional scroll.
Can someone suggest a way to implement this.If possible with pieces of code which is well appreciated.
TNQ
[swipeGesture setCancelsTouchesInView:TRUE];
This will make the gesture recognizer swallow the touches.
Hope this helps.
Cheers!

Assigning an animation to a UIButton

If I have an animation which can play with an array of images.
How Do I set this to play on a button? I want the buttons image to display the animation?
Thanks
If you need an actual button, then the choice is clear: You will need to build your own custom UIControl object to achieve this. Quite possibly you can just subclass UIButton, and handle animating the images that way. I do something similar in one of my apps using core animation to fade between a series of 6 images. It works quite well.
I will point you at the UIControl class reference. Please read the intro material on the page, it links to other pages, like event handling. As well, I will also point you at the CABasicAnimation class reference, with the same caveat applied.
Remember, a UIControl is just a UIView, except that it handles events a particular way.
Simplest way is just to place a custom UIButton (ie invisible to the user) above your UIImageView. Then it will appear that the button is animated but in reality it will be the images underneath the button that are animated.
Create an array, eg. myArray with the filenames of your images.
assign this array to a UIImage with myImage.animationImages = myArray;
then use setImage:forState to assign this animation to the button.

Swipe to change UIViewContent

Hej folks,
I got an UIView in my application and want to implement kind of a swipe gesture. I know how I detect this gesture (touchesBegan: and touchesEnded: for example is x coordinates are distanced more than 100 pixels or something else) but I really donĀ“t now how to animate my needs. In fact my UIView will contain subviews which are 9 UIButtons. On swipe I want to change the set of buttons programatically...any solutions out there? Primarily need the animation!
EDIT: I thought about programatically moving the buttons off-screen to the left and at the same time move the new ones on-screen from the right side. But it seems I don't really know how to realize this...isn't it too much leaking at the same time? Please give me a hint!
It's seem that you want to recreate somethings like the springboard but with button instead of icon.
I can suggest you to use UIScrollView.
why you don't load just a new view with the other button set in your window after the swipe gesture was detected?

How do I programmatically make clicking on a UIImageView do something on the iPhone?

I have programmatically added a UIImageView. How do I make it send a message to my controller when the users clicks it, sending itself as the only parameter?
I wouldn't use a UIImageView unless there was some other compelling reason. I'd just use a custom UIButton and use the UIImage as its background.
Create a new class that extends UIImageView and use that.
In your class, override the touch events - touchesBegan, touchesEnded and/or touchesMoved as appropriate
From those methods, call back to a method on the controller.
I'd just put a custom button over the UIImage view, and use normally - buttons with Custom style are invisible and so will not obscure the image. It's also a great way to turn regions of text into clickable areas as well.
Or, you could assign the custom image as a graphic background for the button.
just put a button over the imageview, with the Alpha attribute set to 0.10 or less.
you can capture the button's tap event but almost cannot see it.