[英]UIView Animation for ImageView in ios
我有必要将网格视图中的图像视图从当前位置动画化为全屏。 我使图像进入网格视图。
- (void)viewDidLoad
{
[super viewDidLoad];
imagesArray = [[NSMutableArray alloc] init];
for (int i=1; i<11; i++) {
[imagesArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"image%d.png", i]]];
NSLog(@"imagesArray:%@", imagesArray);
}
float horizontal = 20.0;
float vertical = 20.0;
for(int i=0; i<[imagesArray count]; i++)
{
if((i%3) == 0 && i!=0)
{
horizontal = 20.0;
vertical = vertical + 220.00 + 20.0;
}
imagesView = [[UIImageView alloc] initWithFrame:CGRectMake(horizontal, vertical, 310.0, 220.00)];
imagesView.userInteractionEnabled = YES;
[imagesView setImage:[imagesArray objectAtIndex:i]];
imagesView.tag = i;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
[imagesView addGestureRecognizer:tap];
[self.view addSubview:imagesView];
horizontal = horizontal + 310.0 + 20.0;
}
}
在这里,我用图像创建了网格视图,就像我有10张图像一样。 我做了3x3网格视图。
接下来,我向其添加了点击手势,并且通过使用标记调用来获取图像视图位置
-(void)handleTap:(UITapGestureRecognizer *)recognizer
{
UIView *piece = recognizer.view;
[UIView animateWithDuration:1.0 animations:^{
piece.frame = CGRectMake(piece.frame.origin.x, piece.frame.origin.y, 1000, 700);
} completion:^(BOOL finished) {
}];
}
您能说我如何通过点击使其从当前位置到全屏动画吗?
由于要将视图添加到视图控制器的self.view
中,因此可以假定self.view
占据了设备的整个屏幕。 因此,您可以为其边界设置动画:
[UIView animateWithDuration:1.0 animations:^{
piece.frame = self.view.bounds;
} completion:nil];
请注意,如果piece
必须具有横跨整个屏幕的父视图,以使您的内部视图在动画期间不会被剪切。
此代码将帮助您添加动画效果,例如缩放您期望的图像视图。 动画结束后,需要自定义以全屏图像视图显示。
-(void)addZoomAnimationToZoomViewController:(UIImageView *)zoomView
{
CABasicAnimation *zoomAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
[zoomAnimation setDuration:0.8];
[zoomAnimation setRepeatCount:1];
[zoomAnimation setFromValue: [NSNumber numberWithFloat:0.1]];
[zoomAnimation setToValue: [NSNumber numberWithFloat:5.0] ];
[zoomAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[zoomView layer] addAnimation:zoomAnimation forKey:@"zoom"];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.