【问题标题】:When I resize a layer of imageview, how can I resize the uiimageview at the same time?当我调整一层imageview的大小时,如何同时调整uiimageview的大小?
【发布时间】:2012-09-03 02:12:14
【问题描述】:

这是我的代码:

CABasicAnimation *animation = [CABasicAnimation 
                               animationWithKeyPath:@"transform.scale"];
[animation setFromValue:[NSNumber numberWithFloat:1.0f]];
[animation setToValue:[NSNumber numberWithFloat:3.0f]];
[animation setDuration:0.8];
[animation setRemovedOnCompletion:NO];
[animation setFillMode:kCAFillModeForwards];
[imageView.layer addAnimation:animation forKey:@"scale"];

[imageView setFrame:nowRect];

我发现这不对,因为当我将imageView框架设置为nowRect时,imageView的层又变大了!

【问题讨论】:

  • 嗨,您的实际需求是什么......
  • 嗨,对不起,我的英语太差了。我想让 imageview 的 frame 成为 imageview 的图层在动画后显示的帧。
  • 你之前和之后的帧大小是多少......
  • 比如老框架是(x,y,width,height)。新框架是(x,y,宽度*3,高度*3)。动画后,我想将imageview的框架设置为与其图层的框架相同。

标签: iphone imageview scale layer cabasicanimation


【解决方案1】:

试试这个,你首先在 viewDidLoad 中设置你的图像大小....

例如: 在此示例中,a 和 b 是您最初需要的大小...

imageForAnimate.frame=CGRectMake(imageForAnimate.frame.origin.x, imageForAnimate.frame.origin.y, a, b); 

然后您需要将此代码附加到您需要的区域...

 [UIView animateWithDuration:0.8 animations:^{
        imageForAnimate.frame=CGRectMake(imageForAnimate.frame.origin.x, imageForAnimate.frame.origin.y, a*3, b*3);


    }]; 

我希望这能帮助你解决....

【讨论】:

  • 谢谢你!!我只想知道当我使用图层的动画时,如何使视图的框架移动到视图的图层所在的框架。但是你的回答说的动画是我想要的。
猜你喜欢
  • 2011-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多