ios - 带有 UIImageView 的 CALayer

标签 ios core-animation

我有以下代码:

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];

}

触发触摸事件时, Logo 会消失,但是当我删除 ca_Logo.duration = 2.0f , 那 ca_Logo会移动,但它不是动画,只是瞬间消失并出现在新位置。

有什么问题吗? img_LogoUIImageViewIBOutlet或者我需要在没有界面生成器的情况下对其进行编程?

我想从 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]; 

关于ios - 带有 UIImageView 的 CALayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19580196/

相关文章:

ios - 如何初始化一个类并快速使用扩展

ios - Xcode 5 - 应用程序通过验证,通过 iTunes 安装后图标变灰

iphone - 利用 OpenGL 中的核心动画制作动画

iphone - iOS打印图像和文本

ios - 使用 UILocalizedIndexedCollat​​ion 在 Swift 4.2 中创建 tableView 部分索引时出现错误 "unrecognized selector sent to instance"

ios - 使用 RESTKit 映射 iTunes 搜索 API 结果

ios - CALayer 扁平子层

ios - 动画 UIImageView 逐行出现在屏幕上

ios - UIView beginAnimations 在自定义属性上太快

ios - CAShapeLayer 动画路径故障/闪烁(从椭圆到矩形再返回)