0

How can I make sure that the images that are within my scroller will be able to be dragged from the scroller to the imageview?

I also would like to implement a 'wiggle'. When a user taps an image within the scroller the images wiggles and follows the touch of the user to the other view. I started with making a subview, however when the image displays itself on the normal view its location changes to be on top of the view instead of on the bottom.

How can I make sure that when I touch an image:

  • the image wiggles
  • the images go to another view.
  • the images follow my touch position

(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:self.view];

    image1.userInteractionEnabled = YES;
    [self.view addSubview:image1];

    if([touch view] == image1){

        image1.center = location;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.14];
        [UIView setAnimationRepeatAutoreverses:YES];
        [UIView setAnimationRepeatCount:1000000];

        image1.transform = CGAffineTransformMakeRotation(69);
        image1.transform = CGAffineTransformMakeRotation(-69);

        [UIView commitAnimations];
        image1.center = CGPointMake(30,870);          
    }

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *) event {

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:self.view];

    if([touch view] == image1){
        image1.userInteractionEnabled = YES;
        [self.view addSubview:image1];
        image1.center = location;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.14];
        [UIView setAnimationRepeatAutoreverses:YES];
        [UIView setAnimationRepeatCount:1000000];

        image1.transform = CGAffineTransformMakeRotation(69);
        image1.transform = CGAffineTransformMakeRotation(-69);

        [UIView commitAnimations];  
    }
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
BarryK88
  • 1,806
  • 2
  • 25
  • 41

1 Answers1

0

In stead of using the 'touches functions' I used gestureRecognizers. You can put a recognizer on a certain image (TapRecognizer of LongpressRecognizer). When a user presses the image the App recognizes the touch. Afterwords you can put the image in a subview on top of your normal view with the function "[self.view addSubview:yourImage];"

Here's a snippit

First you declare the gesturerecognizer in your viewDidLoad, viewDidAppear or viewWillappear method

UILongPressGestureRecognizer *longPress =
    [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
    longPress.minimumPressDuration = 0.7;
    [yourimage addGestureRecognizer:longPress1];

Afterwords you use the delegate function

-(void)longPressed:(UILongPressGestureRecognizer *)sender {

    CGPoint location = [sender locationInView:self.view];

    [self.view addSubview:yourimage];
    yourimage.center = location;
    //perform a transform (wiggle or scale)
    if([(UILongPressGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
        yourimage.transform = CGAffineTransformMakeScale(1.0, 1.0);
        //stop the transform

    }   
}

Hope this helps you out Elppa

BarryK88
  • 1,806
  • 2
  • 25
  • 41