iPhone animation based on input values (touches) not time

后端 未结 5 1413
粉色の甜心
粉色の甜心 2020-12-28 20:30

For an animation effect perfectly suited to an animation group approach as shown in Brad Larson\'s answer here, I need the animation to proceed according to inputs. Specific

5条回答
  •  太阳男子
    2020-12-28 20:54

    If you are targeting iOS 4.0 or greater then you can use the new block based class methods to start animatable changes to view objects. So from your touch event you can initiate an animatable change to properties on the view:

    [UIView animateWithDuration:1.0 animations:^{
        yourView.alpha = 0.0; // fade out yourView over 1 second
    }];
    

    N.B. This could just as easily be a change to another property on the view, like its location. You can animate the following properties on the view this way:

    @property frame
    @property bounds
    @property center
    @property transform
    @property alpha
    @property backgroundColor
    @property contentStretch
    

    If you are targetting earlier versions of iOS you will need to use UIView beginAnimations and commitAnimations methods to create an animation block:

    [UIView beginAnimations:nil context:context];
    [UIView setAnimationDuration:1.0]; 
    yourView.alpha = 0.0;
    [UIView commitAnimations];
    

    This stuff works really well and once you start using it, you will have to be careful you don't get addicted. ;)

    Update for comment:

    You can bind the position of the marble to the location of the touch event. Once you get the touchesEnded event you can then animate the location of the marble using an animation block.

提交回复
热议问题