gpt4 book ai didi

ios - 翻转动画中途更改 UIImageView 图像

转载 作者:可可西里 更新时间:2023-11-01 05:01:16 26 4
gpt4 key购买 nike

如何在 Flip 动画进行到一半时更改 UIImageView 的图像。我的代码似乎确实翻转了 UIImageView 并成功更改了图像,但它正在瞬间改变。我想要实现的是仅在 180 度翻转达到 90 度翻转时才更改图像。这是我的代码:

在 View 上创建 UIImageView:

UIImage *image = [UIImage imageNamed:@"fb1.jpg"];
imageView = [[UIImageView alloc] initWithImage:image];
vw = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)];
vw.layer.cornerRadius = vw.frame.size.width / 2;
imageView.frame = CGRectMake(20, 20, 80, 80);
imageView.layer.cornerRadius = imageView.frame.size.width / 2;
imageView.layer.masksToBounds = YES;
imageView.layer.borderColor = [[UIColor blackColor] CGColor];
imageView.layer.borderWidth = 1.0;
[self.view addSubview: imageView];
//[self.view addSubview:vw];
[imageView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(taptap:)];
[imageView addGestureRecognizer:tap];

在点击时为 UIImageView 设置动画:

[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
imageView.transform = CGAffineTransformMakeScale(-1, 1);
[UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionTransitionCrossDissolve
animations:^(void) {
imageView.image = [UIImage imageNamed:@"fb2.jpg"];
} completion:^(BOOL finished) {

}];
}
completion:^(BOOL finished) {
}];

此外,我在特定 UIImageView 上通过轻击手势制作此动画。

最佳答案

您可以使用 UIView 类方法 + (void)transitionWithView:duration:options:animations:completion: 轻松实现此动画。

为你的动画使用这样的代码:

[UIView transitionWithView:imageView
duration:0.4
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
// Set the new image
// Since its done in animation block, the change will be animated
imageView.image = newImage;
} completion:^(BOOL finished) {
// Do whatever when the animation is finished
}];

您可以通过将 UIViewAnimationOptionTransitionFlipFromRight 替换为以下任何选项来设置翻转方向:

UIViewAnimationOptionTransitionFlipFromLeft
UIViewAnimationOptionTransitionFlipFromRight
UIViewAnimationOptionTransitionFlipFromTop
UIViewAnimationOptionTransitionFlipFromBottom

关于ios - 翻转动画中途更改 UIImageView 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18485711/

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