title: Getting 2 Images to Drag in View Xcode
body: <p>I have 2 images in a view and I applied a drag touch function to the images, and when the image collides with the image at the top of the view it gives you an alert and changes the image at the top of the view to a different image. </p>
  
  <p>My problem is getting my if else statement to work, If i take out the == image in </p>
  
  <pre><code>([touch view] == image) {
  </code></pre>
  
  <p>Only one of the images drag, I cannot seem to get both images to drag. My if else statement has no errors, but does not seem to work.</p>
  
  <p><strong>frfViewController.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface frfViewController : UIViewController {
  UIImageView *image;
  UIImageView *image2;
  UIImageView *images;
  UIImageView *collisionImage;
  
  }
  
  @property (nonatomic, retain) IBOutlet UIImageView *image;
  @property (nonatomic, retain) IBOutlet UIImageView *image2;
  @property (nonatomic, retain) IBOutlet UIImageView *collisionImage;
  @property (nonatomic, retain) IBOutlet UIImageView *images;
  @end
  </code></pre>
  
  <p><strong>frfViewController.m</strong></p>
  
  <pre><code>#import "frfViewController.h"
  
  @interface frfViewController ()
  
  @end
  
  @implementation frfViewController
  
  @synthesize image;
  @synthesize image2;
  @synthesize images;
  @synthesize collisionImage;
  
  - (void)viewDidLoad
  {    
  }
  
  - (void)viewWillAppear:(BOOL)animated
  {
  
  //      [self.navigationController setNavigationBarHidden:YES animated:animated];
  //      [super viewWillAppear:animated];
  }
  
  - (void)viewWillDisappear:(BOOL)animated
  {
  [self.navigationController setNavigationBarHidden:NO animated:animated];
  [super viewWillDisappear:animated];
  }
  
  -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch *touch = [[event allTouches] anyObject];
  CGPoint location = [touch locationInView:self.view];
  
  if ([touch view] == image) {
  
      image.center = location;
      image.userInteractionEnabled = YES;
  
  
  }
  
  else if ([touch view] == image2) {
  
      image2.center = location;
      image2.userInteractionEnabled = YES;
  
  }
  
  [self ifCollided];
  }
  
  -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  [self touchesBegan:touches withEvent:event];
  }
  
  -(void) ifCollided {
  if (CGRectIntersectsRect(image.frame, collisionImage.frame) ||  CGRectIntersectsRect(image2.frame, collisionImage.frame)) {
  
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"image Collided"
                                                      message:@"FuckYea"
                                                     delegate:nil
                                            cancelButtonTitle:@"Reset!"
                                            otherButtonTitles:nil];
      [alert show];
  
      CGRect myImageRect = CGRectMake(0, 0, 320, 100);
      images = [[UIImageView alloc] initWithFrame:myImageRect];
      [images setImage:[UIImage imageNamed:@"004.jpg"]];
      [self.view addSubview:images];
   }
  
  
  }
  
  @end
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/4MzmH.png" alt="enter image description here"></p>
  
  <p>Thanks any assistance is much appreciated.</p>