How to "click" UIImageView?

I have UIViews that I would like the user to “click” on the screen. This is not a scroll. They just contain a bitmap (png). Can someone please give me sample code etc. to help me get started? Is something a little heavier than MoveMe, which helps to detect a “click” (against a “push” or drag) and then displays the view in the “click” direction?

OpenGL is probably a bust. If possible, I would like to stay in the field of Core Graphics / Animation.

+3
source share
6 answers

To detect a touch, in the view controller, you can use the touchhesBegan and touchesEnded methods, save the touch from touchhesBegan, and if the touch moved more than a certain amount to the left or right, it was a click, and not a push to the left or right.

0
source

I would say that a simple way to implement this would be to put your views in a UIScrollView container with paging enabled and let it worry about all the “clicks” of actions. Works great for me.

You can even with some extra effort have a preview of lazy image loading.

+2
source

, , nazgul42 . . , .

+1

, UIView aView UIImageViews, page1 page2. , page1 subview aView, page1 page2:

[UIView beginAnimations:@"someId" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:aView cahe:YES];
[page1 removeFromSuperview];
[aView addSubview:page2];
[UIView commitAnimations];
0

, -

http://discussions.apple.com/message.jspa?messageID=7862186

Speed ​​or time stamps are not taken into account; just the distance since the last update of the event. If Apple has ever changed the frequency / detail of event updates, this code may break.

0
source

try using the UIPanGentureRecognizersample code:

UIPanGestureRecognizer *imageGesture = [[UIPanGestureRecognizer alloc]
                                         initWithTarget:self
                                         action:@selector(imageDragged:)];
[imageView1 addGestureRecognizer:imageGesture];

then

- (void)imageDragged:(UIPanGestureRecognizer *)gesture{
UIImageView *imageView = (UIImageView *)gesture.view;
CGPoint translation = [gesture translationInView:imageView];

imageView.center = CGPointMake(imageView.center.x + translation.x,
                               imageView.center.y + translation.y);
imageView2.center = imageView.center;
imageView3.center = imageView.center;

[gesture setTranslation:CGPointZero inView:imageView];}
0
source

Source: https://habr.com/ru/post/1711286/


All Articles