塊基地動畫的格式是這樣的:
[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];
謝謝@Kjuly您提供的中間代碼塊做了訣竅:) – bennythemink
@bennythemink u'r welcome :) – Kjuly