gpt4 book ai didi

iphone - 手势识别器和 UIImageView

转载 作者:行者123 更新时间:2023-11-28 20:40:59 25 4
gpt4 key购买 nike

我发现这段代码可以在点击时更改图像。

在 .h 中

@interface MyappViewController : UIViewController 
{
NSDictionary *ddata;
UIImageView *firstImage;
}
@property(retain,nonatomic) IBOutlet UIImageView *firstImage;

.m

- (void)viewDidLoad
{
[super viewDidLoad];

firstImage.userInteractionEnabled = YES;
UIPinchGestureRecognizer *pgr = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(clickHandler:)];
pgr.delegate = self;
[firstImage addGestureRecognizer:pgr];
[pgr release];
// [self clickHandler:self];
}

-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
/* destroy the transition view, set the image first */
UIImageView *transitionImageView = (UIImageView *)context;
self.firstImage.image = transitionImageView.image;
[transitionImageView removeFromSuperview];
transitionImageView = nil;
}

- (void)clickHandler:(id)sender {
/* temporary view for the animation */
NSLog(@"Click Handled ");

UIImageView *transitionImageView = [[UIImageView alloc] initWithFrame:self.firstImage.frame];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[ddata objectForKey:@"pic"]]]];
transitionImageView.image = image;
transitionImageView.alpha = 0.0f;
[self.view addSubview:transitionImageView];

[UIView beginAnimations:@"UpdateImages" context:transitionImageView];
[UIView setAnimationDuration:2.0f];
transitionImageView.alpha = 1.0f;
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}

当我点击图片时没有任何反应,但是如果我调用 [self clickHandler:self];在 ViewDidLoad 中,图像发生变化。我的问题是当我点击图片时没有处理点击。

最佳答案

您需要使用 UITapGestureRecognizer 而不是 UIPinchGestureRecognizer。不要忘记设置所需的点击次数和手指数量等内容。这些文档非常适合手势识别器。

关于iphone - 手势识别器和 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8566116/

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