[英]Create custom animation like transitionWithView block
I am using transitionWithView
animation block to animate view. 我正在使用transitionWithView
动画块对视图进行动画处理。 This block is called when user swipe the view in left or right direction. 当用户向左或向右滑动视图时,将调用此块。 It works fine. 工作正常。 But I want to create my own custom animation like view gets changed from left to right direction. 但是我想创建自己的自定义动画,例如视图从左向右更改。 I don't know how to achieve this. 我不知道该如何实现。 I am using UIViewAnimationOptionTransitionCurlUp
for right to left swipe and UIViewAnimationOptionTransitionCurlDown
for left to right swipe in UIViewAnimationOptions
. 我使用UIViewAnimationOptionTransitionCurlUp
从右到左轻扫和UIViewAnimationOptionTransitionCurlDown
在左到右轻扫UIViewAnimationOptions
。
[UIView transitionWithView:self.view duration:0.6 options:UIViewAnimationOptionTransitionCurlUp animations:^{
setDataInLayout();
} completion:^(BOOL finished) {
[scrollViewContent setContentOffset:CGPointZero animated:YES];
[self.delegate updatePaginationCounter:_currentStoneIndex];
}];
You have to implement this animation by yourself. 您必须自己实现此动画。 I would use UIView animation API like: 我将使用UIView动画API,例如:
UIView.animateWithDuration(0.6, animations: {
// apply 2D transformation to the view, or use any other animatable property
self.view.transform = CGAffineTransformMakeRotation(fullRotation)
} completion: {finished in
// you completion block
})
Here is the list of UIView's animatable properties. 这是UIView的动画属性列表 。 For more complex animations you can use the keyframe-based animation: 对于更复杂的动画,可以使用基于关键帧的动画:
UIView.animateKeyframesWithDuration(duration, delay: delay, options: options, animations: {
// add your keyframe animations here
UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 1/2, animations: {
self.view.transform = ...
})
UIView.addKeyframeWithRelativeStartTime(1/3, relativeDuration: 1/2, animations: {
self.view.transform = ...
})
}, completion: {finished in
// completion block
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.