这两者有什么区别?
我相信他们有利有弊,而且他们的表现更好.
比较两者的任何资源?
动画是否更好(我想象CATransform3D)?为什么?
另外我想我在某处读到文字清晰度可能是一个问题,是否更适合缩放文本?
我有一个实例,MKMapView并希望使用自定义注释图标,而不是MKPinAnnotationView提供的标准图钉图标.所以,我已经设置了一个名为CustomMapAnnotation的MKAnnotationView的子类,并且重写-(void)drawRect:了绘制CGImage.这有效.
当我尝试复制.animatesDropMKPinAnnotationView提供的功能时出现问题; 当注释被添加到MKMapView实例时,我希望我的图标能够逐渐显示,从上到下以及从左到右顺序显示.
这是 - (void)drawRect:用于CustomMapAnnotation,当你只绘制UIImage(这是第二行所做的)时它可以工作:
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
[((Incident *)self.annotation).smallIcon drawInRect:rect];
if (newAnnotation) {
[self animateDrop];
newAnnotation = NO;
}
}
Run Code Online (Sandbox Code Playgroud)
添加animateDrop方法时出现问题:
-(void)animateDrop {
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGPoint finalPos = self.center;
CGPoint startPos = CGPointMake(self.center.x, self.center.y-480.0);
self.layer.position = startPos;
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"position"];
theAnimation.fromValue=[NSValue valueWithCGPoint:startPos];
theAnimation.toValue=[NSValue valueWithCGPoint:finalPos];
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;
theAnimation.delegate = self;
theAnimation.beginTime = 5.0 * (self.center.x/320.0);
theAnimation.duration = 1.0;
[self.layer addAnimation:theAnimation …Run Code Online (Sandbox Code Playgroud) " 仪器用户指南"有这样的说法:
- 彩色复印图像.将青色叠加层放在Core Animation复制的图像上.
但这并不能解释为什么要复制图像.从一个复制的图像到另一个复制图像似乎没有明显的模式,尽管它是规则的和可重复的.
该文档目前甚至没有提到颜色点击绿色和红色小姐,但我想它可能有一些做CALayer的shouldRasterize财产.
有任何想法吗?
我想使用CGPathRef缩放和滚动UIScrollView.因此我假设我必须为UIScrollView的图层属性设置动画?但是我会设置哪个属性动画会使它等同于执行UIView动画并设置其contentOffset属性和zoomScale?
这些不是CALayer的属性.
关于我如何处理这个问题的任何想法?同样,只想将滚动视图移动到某个contentOffset和zoomScale,但不一定是从A点到B点的线性移动,分别是缩放A到缩放B.
我正在考虑使用CGPathRef的CAKeyFrameAnimation,但我不知道要设置动画的属性.
在我们的应用程序中,我们在CAEAGLLayer上面有UIScrollView.UIScrollView包含一些UIViews(红色矩形).在CAEAGLLayer中,我们绘制白色矩形.白色矩形的中心与红色矩形的中心相同.当UIScrollView滚动时,我们更新CAEAGLLayer中白色矩形的位置并渲染它们.
我们得到了预期的结果:白色矩形的中心总是与红色矩形的中心相同.
但是我们无法将CAEAGLLayer的更新与UIScrollView中的视图移动同步.我们有一些错误 - 红色矩形落后于白色矩形.
粗略地说,我们真的想让CAEAGLLayer与UIScollView一起延迟.
我们准备了示例代码.在设备上运行并滚动,您将看到白色矩形(由OpenGL绘制)比红色矩形(常规UIViews)移动得更快.在scrollViewDidScroll:委托调用中正在更新OpenGL.
https://www.dropbox.com/s/kzybsyu10825ikw/ios-opengl-scrollview-test.zip
它在iOS模拟器中的行为相同,只需看一下视频:http://www.youtube.com/watch?v = 1T9hsAVrEXw
红色= UIKit,白色= OpenGL
代码是:
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
// reuses red squares that are gone outside thw bounds
[overlayView updateVisibleRect:CGRectMake(...)];
// draws white squares using OpenGL under the red squares
[openGlView updateVisibleRect:CGRectMake(...)];
}
Run Code Online (Sandbox Code Playgroud)
在简化的样本中可以很容易地证明同样的问题.工作的xcodeproj可以在以下位置找到:
https://www.dropbox.com/s/vznzccibhlf8bon/simple_sample.zip
示例项目基本上在OpenGL中绘制和动画一组WHITE方块,并为RED组的UIViews做同样的操作.红色和白色方块之间很容易看到滞后.
modalTransitionStyle我想添加一个CAAnimation(或其他东西),而不是设置uiviewcontroller .此代码可以在navigationController中执行自定义动画
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:adjustViewController animated:NO];
Run Code Online (Sandbox Code Playgroud)
如何将其实现到模态视图控制器?
我想以与UIAlertView相同的方式呈现一个视图 - 一个流行/弹簧.不幸的是,子类化UIAlertView不是我需要呈现的视图的选项.我已经写了一些代码,但我似乎无法像我想的那样实现它.如果有任何相似之处(我在Google上找不到任何内容),我将不胜感激任何有关更大现实主义或链接的建议.谢谢.
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
self.backgroundColor = [UIColor whiteColor];
v = [[UIView alloc] initWithFrame:CGRectMake(140, 140, 60, 60)];
v.backgroundColor = [UIColor blueColor];
[self addSubview:v];
[self animate];
}
return self;
}
- (void)animate {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(popStep1Complete)];
v.frame = CGRectMake(90, 90, 140, 140);
[UIView commitAnimations];
}
- (void)popStep1Complete {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.15];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(popStep2Complete)];
v.frame = CGRectMake(110, 110, 100, 100);
[UIView …Run Code Online (Sandbox Code Playgroud) 我无法弄清楚如何使用CATransform3DMakeRotation().有人可以告诉我如何使用它吗?
我认为第一个参数是角度,对吧?但是其他三个是什么?
我正在开发一个我想在Mac和iOS上使用的CATextLayer.我可以控制图层中文本的垂直对齐方式吗?
在这种特殊情况下,我希望将其垂直居中 - 但有关其他垂直对齐的信息也会引起关注.
编辑:我发现了这个,但我不能让它发挥作用.
我在iOS中有一个非常简单的动画,它会淡化视图,调整容器大小以适应另一个视图,然后淡化其他视图.这很容易做到且非常简单.
我一直在尝试在OSX上做一些非常类似的事情,但我还没弄清楚如何做到这一点.与iOS相比,OSX上的动画内容感觉非常笨重和困难.
任何帮助将非常感激!!
谢谢!:)
// Fade out viewOne, resize frame to fit viewTwo, fade in viewTwo
[UIView animateWithDuration: 0.15
animations: ^{
[viewOne setAlpha:0.0];
}
completion: ^(BOOL finished) {
[UIView animateWithDuration: 0.2
animations: ^{
[self setFrame: [viewTwo frame]];
}
completion: ^(BOOL finished) {
[viewTwo setAlpha: 0.0];
[self addSubview: viewTwo];
[UIView animateWithDuration: 0.15
animations: ^{
[viewTwo setAlpha:1.0];
}];
}];
}];
Run Code Online (Sandbox Code Playgroud) core-animation ×10
iphone ×5
ios ×4
cocoa ×2
cocoa-touch ×2
macos ×2
instruments ×1
mapkit ×1
opengl-es ×1
uikit ×1
uiscrollview ×1
uiview ×1