iOS动画专家!每种方法的优缺点是什么?我知道Apple推荐的是块而不是旧的UIView动画方法(UIView beginAnimations等等),但是呢CAAnimation?你什么时候使用一种方法而不是另一种?在性能方面有权衡吗?
我想动画重新加载一个集合视图,这样当一个单元格被选中时,我得到的动画类似于在单人纸牌游戏中发牌.(成像旧的MS纸牌)
我一直在寻找"自定义UICollectionView重载动画",并看到了诸如此类的解决方案
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadItemsAtIndexPaths:myindexPaths]
} completion:nil];
Run Code Online (Sandbox Code Playgroud)
并且想到了这一点
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
[self.collectionView.layer addAnimation:transition forKey:nil];
[self.collectionView reloadData];
return;
Run Code Online (Sandbox Code Playgroud)
但它没有达到我想要的效果.有什么想法可以做到吗?
caanimation uiviewanimation ios uicollectionview uicollectionviewlayout
我想交叉淡化两个NSViews并调整它们的大小NSWindow.我知道如何单独进行,但到目前为止还不知道如何同时进行.我想我需要CAAnimationGroup它.但是因为我正在处理两个不同的对象,我不知道如何在组中添加两个动画,我不知道如何启动动画,因为我无法同时调用animator它们.
假设我想在视图中添加50个图像以便为它们制作动画.让我们假设我正在计划使用Core Animation(例如,CABasicAnimation)而不是"UIView"动画.
我最好通过添加50个子视图或50个子图层来实现这一点吗?这有什么不同吗?
谢谢.
我对CABasicAnimation有一些问题.它类似于那篇文章:CABasicAnimation旋转返回到原始位置
所以,我有在touchMove中旋转的uiimageview.在touchEnd调用方法做"惯性动画":
-(void)animationRotation: (float)beginValue
{
CABasicAnimation *anim;
anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
anim.duration = 0.5;
anim.repeatCount = 1;
anim.fillMode = kCAFillModeForwards;
anim.fromValue = [NSNumber numberWithFloat:beginValue];
[anim setDelegate:self];
anim.toValue = [NSNumber numberWithFloat:(360*M_PI/180 + beginValue)];
[appleView.layer addAnimation:anim forKey:@"transform"];
CGAffineTransform rot = CGAffineTransformMakeRotation(360*M_PI/180 + beginValue);
appleView.transform = rot;
}
Run Code Online (Sandbox Code Playgroud)
这个动画工作正常,但如果我在animationRotation结束前调用touchBegan,则旋转角度为beginValue.我需要阴极电流旋转角度.作为一个实验,我宣布方法
-(vod) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
NSLog(@"Animation finished!");
}
Run Code Online (Sandbox Code Playgroud)
它看起来很有效.但我不知道如何在animationDidStop中为我的UIImageView获取角度值或CGAffineTransform.甚至可以做到吗?谢谢.
我发现UIImageView在两个状态之间设置动画是很棘手的:它的原始矩形框架和用a创建的新形状UIBezierPath.提到了许多不同的技术,其中大部分对我不起作用.
首先是认识到使用UIView块动画不起作用; 显然,无法在animateWithDuration:块中执行子图层动画.(见这里和这里)
剩下的CAAnimation就是具体的子类CABasicAnimation.我很快就意识到,一个人不能从一个没有一个的视图中动画CAShapeLayer(例如,见这里).
并且它们不能只是任何两个形状层路径,而是"动画形状层的路径只能保证在你喜欢的时候动画"(见这里)
有了它,就会出现更普通的问题,例如使用什么fromValue和toValue(它们应该是a CAShapeLayer还是a CGPath?),将动画添加到(layer或者mask?)等等.
似乎有很多变数; 哪个组合会给我我想要的动画?
如何在iOS中实现子类的kCATransitionPush使用CAAnimation?
CAAnimation *animation;
// How do you create an animation that does the same than:
// CATransition *animation = [CATransition animation];
// [animation setType:kCATransitionPush];
[self.view.layer addAnimation:animation forKey:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[self.view addSubview:change];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
我知道也可以使用UIView动画,但是如果我可以实现从头开始的转换,它将有助于我更好地理解核心动画.kCATransitionPush
我有一个CALayer子类,其float animAngle属性标记为@dynamic.我已经实现的方法actionForKey,initWithLayer,needsDisplayForKey和drawInContext为子类.定义actionForKey如下
- (id<CAAction>)actionForKey:(NString *)event {
if([event isEqualToString:@"animAngle"]) {
return [self animationForKey:event];
}
return [super actionForKey:event];
}
Run Code Online (Sandbox Code Playgroud)
和
- (CABasicAnimation *)animationForKey:(NSString *)key
{
NSString *animValue = [[self presentationLayer] valueForKey:key];// Logs as 0
CABasicAnimation *anim;
if([key isEqualToString:@"animAngle"]) {
anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
anim.repeatCount = HUGE_VAL;
anim.autoreverses = YES;
//anim.fromValue = [[self presentationLayer] valueForKey:key]; // setting animation value from layer property as in here does not work. …Run Code Online (Sandbox Code Playgroud) 我正在尝试将图像拼接成预先存在的视频,以便在Mac上使用AVFoundation创建新的视频文件.
到目前为止,我已经阅读了Apple文档示例,
ASSETWriterInput用于在Iphone问题上从UIImages制作视频
使用AVVideoCompositionCoreAnimationTool在CALayer中将视频与静态图像混合
AVFoundation教程:为视频和其他一些SO链接添加叠加和动画
现在这些已经被证明是非常有用的,但我的问题是我没有创建一个静态水印或覆盖,我想在视频的各个部分之间插入图像.到目前为止,我已经设法获取视频并创建空白部分以插入这些图像并将其导出.
我的问题是让图像在这些空白部分插入自己.我可以看到可行的唯一方法是创建一系列动画层,以便在正确的时间改变它们的不透明度,但我似乎无法让动画工作.
下面的代码是我用来创建视频片段和图层动画的代码.
//https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_Editing.html#//apple_ref/doc/uid/TP40010188-CH8-SW7
// let's start by making our video composition
AVMutableComposition* mutableComposition = [AVMutableComposition composition];
AVMutableCompositionTrack* mutableCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableVideoComposition* mutableVideoComposition = [AVMutableVideoComposition videoCompositionWithPropertiesOfAsset:gVideoAsset];
// if the first point's frame doesn't start on 0
if (gFrames[0].startTime.value != 0)
{
DebugLog("Inserting vid at 0");
// then add the video track to the composition track with a time range from 0 to the first point's startTime
[mutableCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, gFrames[0].startTime) ofTrack:gVideoTrack atTime:kCMTimeZero …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个动画,它基本上只是进行UIButton增长和收缩,以便用户可以明显地点击他们。
问题是,虽然它在视图第一次出现时工作正常,但如果我转到不同的视图控制器(带有 segue)然后返回(什么也没发生),它就不起作用。
这是我的代码:
override func viewWillAppear(animated: Bool) {
expandAnimation()
}
func expandAnimation() {
var animation = CABasicAnimation(keyPath: "transform.scale")
animation.toValue = NSNumber(float: 0.9)
animation.duration = 1
animation.repeatCount = 100
animation.autoreverses = true
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
appDevButton.layer.addAnimation(animation, forKey: nil)
}
Run Code Online (Sandbox Code Playgroud)
我确定这是一个简单的修复,但我在网上找不到任何信息。
caanimation ×10
ios ×9
calayer ×2
swift ×2
animation ×1
avfoundation ×1
catransition ×1
cgimage ×1
cocoa ×1
iphone ×1
macos ×1
nsview ×1
nswindow ×1
objective-c ×1
rotation ×1
uibezierpath ×1
uiview ×1
xcode4 ×1