[英]CALayer with UIImageView
我有下面的代码:
IBOutlet UIImageView *img_Logo;
...
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
CALayer *ca_Logo = img_Logo.layer;
ca_Logo.position = CGPointMake(400, 400);
ca_Logo.duration = 2.0f;
[ca_Logo setNeedsDisplay];
}
当触发触摸事件时,徽标将消失,但是当我删除ca_Logo.duration = 2.0f
,该ca_Logo
将移动,但它不是动画,只是立即消失并显示在新位置。
它有什么问题吗? img_Logo
是一个带有IBOutlet
的UIImageView
,还是我需要在没有Interface builder的情况下对其进行编程?
我想将图像从CGPointMake(400, 400)
CGPointMake(200, 400)
CGPointMake(400, 400)
到CGPointMake(200, 400)
我认为您需要在不使用界面构建器的情况下对其进行编程尝试此代码
UIImage *image = [UIImage imageNamed:@"img_Logo.png"];
CALayer *img = [CALayer layer];
img.contents = (id)image.CGImage;
img.bounds = CGRectMake(0, 0, 100, 200);
img.position = CGPointMake(400, 400);
[self.view.layer addSublayer:img];
如果你只是想从一帧到另一帧动画,请尝试以下方法:
[UIView animateWithDuration:1.0 animations:^{
[self.img_Logo setFrame:CGRectMake(200, 400, youImageViewWidth, youImageViewHeight)];
}];
我没有使用touchesBegan和touchesMoved得到你的观点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.