-1

Im making a single view application where I want a UI image to move from one side of the screen to an other. I want to detect a touch on this image. I cannot use a button because I cannot make the button move. More precision: When i click on the UI image, I want a label to show and to not be hidden anymore. I cant use a UI button because while I click on the image, the image will be moving and buttons cannot move. I hope this is more clear. This is the code up to now:

@IBAction func Start1(sender: UIButton) {
Person1.center = CGPointMake(160, 450) ;
[UIView.animateWithDuration(3,
    animations: { self.Person1.center = CGPointMake(160, 70 )
})];
}
@IBOutlet var Person1: UIImageView!

Thank you

Anton O.
  • 653
  • 7
  • 27
  • http://stackoverflow.com/questions/19611601/ios-detect-tap-down-and-touch-up-of-a-uiview The answer is in objective-c, but from what I've seen of swift, the methods are the same. Just convert the syntaxes. – ReverseEffect Nov 18 '15 at 01:31
  • Why can a button not move? – Tim Nov 18 '15 at 02:14

2 Answers2

1

What I understand that you want a swipe gesture on your screen. Here is the code to add swipe gesture

UISwipeGestureRecognizer *swipeRightBlack = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToRightWithGestureRecognizer:)];
    swipeRightBlack.direction = UISwipeGestureRecognizerDirectionRight;
    [self.viewBlack addGestureRecognizer:swipeRightBlack];

If you want to add single touch gesture too.

UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)];

Here is a nice explanation to add different gesture in your project.

MD Aslam Ansari
  • 1,565
  • 11
  • 19
0

I'm not quite sure I understand what you mean, but if you want to make the picture automatically move from one position to another location, you can directly write two points out, then go to animation is realized. Or do you want to drag the moving images, then you need to add a drag gesture UIPanGestureRecognizer to UIImageView, and then according to the drag drag position get pictures move.

KPrince36
  • 2,886
  • 2
  • 21
  • 29
  • Sorry... thank you for you response let me explain it to you better. – Anton O. Nov 18 '15 at 01:22
  • When i click on the UI image, I want a label to show and to not be hidden anymore. I cant use a UI button because while I click on the image, the image will be moving and buttons cannot move. I hope this is more clear. – Anton O. Nov 18 '15 at 01:25
  • In fact, I feel the two plans will do. Button may be used. Because the button itself has click gesture events, you can go to rewrite this event activities accordingly. Or you can use the label to show and hide. This is absolutely, if your code does not implement the behavior, so a careful look at the code. – yunfei.sun Nov 18 '15 at 04:45