Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should do the trick</p> <pre><code>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ CALayer *rocketPresentationLayer = [self.rocket.layer presentationLayer]; self.rocket.layer.position = rocketPresentationLayer.position; [UIView animateWithDuration:3 delay:0 options:UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionBeginFromCurrentState animations:^(){self.rocket.frame=CGRectMake(self.rocket.frame.origin.x, -40, 25, 40);} completion:^(BOOL finished){}]; } </code></pre> <p><strong>Note 1:</strong> I didn't put logic in here to check whether the user tapped the rocket again, when it is taking off vertically. You might want to add a <code>BOOL</code> or something to see if the user successfully hit the rocket or not, and if so, don't perform the vertical animation again.</p> <p><strong>Note 2:</strong> If in future you only want this to occur when the rocket is hit, you can use <code>hitTest</code> checking to call the animation conditionally.</p> <pre><code>// Get the touch UITouch *touch = [touches anyObject]; CGPoint touchPoint = [touch locationInView:self.view]; // See if we hit the rocket CALayer *rocketPresentationLayer = [self.rocket.layer presentationLayer]; CALayer* hitTest = [rocketPresentationLayer hitTest:touchPoint]; // If we did, then stop animation and move upwards if (hitTest) { .... } </code></pre> <p><strong>P.S:</strong> Also as a slight mention, <code>@property UIImageView *rocket;</code> should be changed to <code>@property (nonatomic) UIImageView *rocket;</code>. This is primarily for performance reasons, as I don't expect your rocket to be accessed by multiple threads (it shouldn't, it's the UI!).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload