我正在向我的应用程序添加一个containerView。这个视图视图和图层位于正常的0,0点和320,480。没有什么令人兴奋或不同的东西。
所以我将它添加到我的视图中,但我想通过它的层在屏幕上对它进行动画处理。再说一次,没什么疯狂的。但是我希望我添加的视图的这个视图/层位于20,160点。所以从左边到窗口中间的20个像素(窗口的下半部分)。我想我会将CALayer的animateToPoint设置为20,160。但它不起作用。
下面是我的代码,它将添加的视图/层动画化为从左侧到屏幕中间的20个像素。问题是,我传递给20,160的点是完全错误的,但它是有效的(我必须通过尝试错误来移动它)。我的问题是为什么20,160不适用于CABasicaAnimation点?为什么我要放入这么大的数字?
// Place the container view
self.callDetailView.view.frame = CGRectMake(20, 163, 280, 263);
self.callDetailView.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.callDetailView.view];
[self addChildViewController:self.callDetailView];
[self.callDetailView didMoveToParentViewController:self];
[self.callDetailView configureDetails:[[STRequestManager sharedInstance] shouldGetCurrentRequest]];
CGPoint myNewEndPoint = CGPointMake(160.0, 263.0); // <-- I would think this should be 20,160
CABasicAnimation *slideIn = [CABasicAnimation animationWithKeyPath:@"position"];
slideIn.duration = 0.5;
[slideIn setToValue:[NSValue valueWithCGPoint:myNewEndPoint]];
[slideIn setFromValue:[NSValue valueWithCGPoint:CGPointMake(160.0, 663.0)]];
[[self.callDetailView.view layer] addAnimation:slideIn forKey:@"mySlideInAnimation"];
[[self.callDetailView.view layer] setPosition:myNewEndPoint];//更新
现在我看160,263是垂直中心点和水平中心点。我添加的视图是280,所以一半是140。140加上我左边的20等于160。CABasicAnimation会为中心设置动画吗?
发布于 2014-09-15 11:11:42
默认情况下,层的AnchorPoint为(0.5,0.5),即居中。因此,您的动画将沿着中心移动。
https://stackoverflow.com/questions/25839858
复制相似问题