gpt4 book ai didi

iphone - 如何使用 UIGestureRecognizers 在多个 UIView 或 UIImageView 上进行点击、捏合和旋转

转载 作者:行者123 更新时间:2023-11-28 18:37:16 24 4
gpt4 key购买 nike

我不知道如何处理:-/

我只需要在图片上添加贴纸。应用程序将在选择特定贴纸时包含表情符号,心形(图像)等贴纸,它将添加到主图像中,用户可以使用贴纸进行操作,例如旋转,缩放等,用户可以选择多个贴纸并可以进行旋转缩放等添加贴纸,

请指导如何实现这一点,我能够使用单个贴纸执行图像操作我不知道如何执行多个贴纸选择,用户可以再次返回到任何贴纸并对其执行操作。

最佳答案

您可以使用此方法添加手势:

- (void) addGestureRecognizers{
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[self addGestureRecognizer:panRecognizer];

UIRotationGestureRecognizer *rotateRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
self.multipleTouchEnabled = YES;
[self addGestureRecognizer:rotateRecognizer];

UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
[self addGestureRecognizer:pinchRecognizer];

UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
longPressRecognizer.minimumPressDuration = 2.0;
[self addGestureRecognizer:longPressRecognizer];
}

并实现这些选择器:

- (void) move:(UIPanGestureRecognizer *)recognizer{
CGPoint translation = [recognizer translationInView:self.superview];
recognizer.view.center = CGPointMake(recognizer.view.center.x+translation.x, recognizer.view.center.y+translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.superview];
}

- (void) rotate:(UIRotationGestureRecognizer *)recognizer{
NSLog(@"Rotate");
recognizer.view.transform = CGAffineTransformRotate(
recognizer.view.transform,
recognizer.rotation);
recognizer.rotation = 0;
}

- (void) pinch:(UIPinchGestureRecognizer *)recognizer{
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = 1;
}

- (void) longPressed:(UILongPressGestureRecognizer *)recognizer{
NSLog(@"Long Pressed");
}

注意:根据需要更改值

关于iphone - 如何使用 UIGestureRecognizers 在多个 UIView 或 UIImageView 上进行点击、捏合和旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16522591/

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