我的UIImageView
应该来自size (0,0) --> (93,75)
我有以下
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionTransitionNone
animations:^{
imgButton.layer.anchorPoint = CGPointMake(imgButton.bounds.size.width/2, imgButton.bounds.size.height/2);
CGRect btnFrame = imgButton.frame;
btnFrame.size.width = 105;
btnFrame.size.height = 85;
imgButton.frame = btnFrame;
}
completion:^(BOOL finished) {
[self animageButton2:imgButton];
}];
这是有效的,但我唯一的问题是它不是从UIImageView
的中心动画,而是从左上角动画。
有人知道吗?
答案 0 :(得分:4)
我在Borrden的帮助下解决了这个问题。这就是我的解决方案。
首先创建一个imageview
UIImageView *imgLineup = [[UIImageView alloc]initWithFrame:CGRectMake(10, y, 93, 75)];
imgLineup.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.0, 0.0);
然后是以下内容。
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut
animations:^{
imgButton.layer.anchorPoint = CGPointMake(0.5, 0.5);
imgButton.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
}
completion:^(BOOL finished) {
NSLog(@"done");
}];
答案 1 :(得分:2)
试试吧。导入#import <QuartzCore/QuartzCore.h>
然后将uimageView添加到self.view
CABasicAnimation *zoomAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
[zoomAnimation setDuration:0.8];
[zoomAnimation setRepeatCount:1];
[zoomAnimation setFromValue:[NSNumber numberWithFloat:0.1]];
[zoomAnimation setToValue:[NSNumber numberWithFloat:1.0]];
[zoomAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[imageView layer] addAnimation:zoomAnimation forKey:@"zoom"];
答案 2 :(得分:0)
我的建议可能是一种破解,但它将是一种更容易实现你想要的方式:
您将imageView的初始帧设置为:
CGRectMake(center, center, 0, 0);
所以在你的情况下,它会更接近:
CGRectMake(46, 37, 0, 0);
然后使用类似这样的新rect进行动画处理:
CGRectMake(0, 0,93,75);
你可以使用简单的UIViewAnimation;
[UIView beginAnimations:@"zoom" context:NULL];
[UIView setAnimationDuration:0.3];
imageView.frame = CGRectMake(0, 0, 93, 75); ;
[UIView commitAnimations];
希望它有效
答案 3 :(得分:0)
您要实现的是缩放变换,即将UIView大小设置为从大小(0,0)到大小(w,h)的动画。 CGAffineTransformMakeScale
可以达到同样的效果。
最初,当您创建视图时,应用CGAffineTransformMakeScale(0.0,0.0)
,然后动画大小可扩展至CGAffineTransformMakeScale(1.0,1.0)
。
代码:
// Create the view and apply correct frame
UIView *tagView = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 100, 100)];
tagView.tag = kTag;
//Apply scale transform, to make size(0,0)
tagView.transform = CGAffineTransformMakeScale(0,0);
[self.view addSubview:tagView];
/// ............
UIView *tagView = [self.view viewWithTag:kTag];
//Now animate the view size scale up
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
tagView.transform = CGAffineTransformMakeScale(1.0,1.0);
}
completion:NULL
];
此动画将根据需要围绕视图的中心点进行,因此无需使用anchorPoint
和frame
,这可能很棘手。详细了解this answer中frame
和anchorPoint
之间的关系。