Формат блочной анимации выглядит следующим образом:
[UIView animateWithDuration:<#(NSTimeInterval)#>
delay:<#(NSTimeInterval)#>
options:<#(UIViewAnimationOptions)#>
animations:<#^(void)animations#>
completion:<#^(BOOL finished)completion#>];
И приведенный ниже код отображает представление twice
и go back to origin position
, , может быть, существует лучший способ :
[UIView animateWithDuration:0.2f
delay:0.0f
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionCurveEaseInOut
animations:^{
self.view.center = CGPointMake(self.view.center.x + 10, self.view.center.y);
}
completion:^(BOOL finished) {
self.view.center = CGPointMake(self.view.center.x - 10, self.view.center.y);
[UIView animateWithDuration:0.2f
delay:0.0f
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionCurveEaseInOut
animations:^{
self.view.center = CGPointMake(self.view.center.x + 10, self.view.center.y);
}
completion:^(BOOL finished) {
self.view.center = CGPointMake(self.view.center.x - 10, self.view.center.y);
}];
}];
И этот похож, но go back to origin position not smoothly
.
[UIView animateWithDuration:0.2f
delay:0.0f
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionCurveEaseInOut
animations:^{
self.view.center = CGPointMake(self.view.center.x + 10, self.view.center.y);
self.view.center = CGPointMake(self.view.center.x - 10, self.view.center.y);
}
completion:nil];