gpt4 book ai didi

ios - ios中ImageView的UIView动画

转载 作者:行者123 更新时间:2023-11-29 03:48:47 25 4
gpt4 key购买 nike

我的要求是我必须将 ImageView 从当前位置动画到 GridView 中的全屏。我将图像制作成 GridView 。

- (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;
}

}

这里我创建了带有图像的 GridView ,就像我有 10 张图像一样。我制作了 3x3 GridView 。

接下来我添加了点击手势,并且我通过使用标签调用来获取 ImageView 位置

-(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) {

}];

}

你能告诉我如何通过点击 ImageView 从当前位置到全屏显示动画吗?

最佳答案

由于您要将 View 添加到 View Controller 的 self.view 中,因此您可以假设 self.view 占据了设备的整个屏幕。因此,您可以为其边界设置动画:

[UIView animateWithDuration:1.0 animations:^{
piece.frame = self.view.bounds;
} completion:nil];

请注意,if piece 必须有一个跨越整个屏幕的父 View ,以便您的内部 View 在动画过程中不会被剪裁。

关于ios - ios中ImageView的UIView动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17335353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com