创建自定义动画,如transitionWithView块

时间:2015-11-19 11:03:52

标签: ios objective-c iphone ipad

我使用transitionWithView动画块来制作视图动画。当用户向左或向右滑动视图时,将调用此块。它工作正常。但我想创建自己的自定义动画,如视图从左向右改变。我不知道如何实现这一目标。我正在使用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];
    }];

1 个答案:

答案 0 :(得分:0)

您必须自己实施此动画。我会使用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    
})

这是UIView动画属性的list。对于更复杂的动画,您可以使用基于关键帧的动画:

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
})
}
相关问题