- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用手势缩放和旋转 UIImageView。我在 Internet 上看到了几个示例并且我已经实现了它,但是它不能一起工作。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
// imgView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
imgView.image = [UIImage imageNamed:@"spotItInLondonIcon.png"];
[imgView setContentMode:UIViewContentModeScaleAspectFit];
[imgView setMultipleTouchEnabled:YES];
[imgView setUserInteractionEnabled:YES];
[self.view addSubview:imgView];
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
[imgView addGestureRecognizer:pinch];
pinch.delegate = self;
UIRotationGestureRecognizer *rotate = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];
[imgView addGestureRecognizer:rotate];
rotate.delegate = self;
}
-(void)pinch: (UIPinchGestureRecognizer*)sender
{
CGFloat scale = sender.scale;
imgView.transform = CGAffineTransformScale(imgView.transform, scale, scale);
sender.scale = 1.0;
NSLog(@"pinch executed");
}
-(void)rotation: (UIRotationGestureRecognizer*)rotationDetected
{
CGFloat angle = rotationDetected.rotation;
imgView.transform = CGAffineTransformRotate(imgView.transform, angle);
rotationDetected.rotation = 0.0;
NSLog(@"rotation executed");
}
@interface ViewController : UIViewController <UIGestureRecognizerDelegate>
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
最佳答案
应用程序 delegate.m 的方法??您必须在要添加手势的类中添加方法,在您的情况下,viewcontroller.m
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
关于objective-c - 使 UIPinchGestureRecognizer 和 UIRotationGestureRecognizer 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13893887/
我想在我的 iPhone 应用程序中使用捏合手势实现缩放。问题是,在识别手势时调用的方法中,我无权访问触摸事件本身(因此我无法真正获取它们的 locationInView:),并且我想获取它以便我的放
我在 ScrollView 中添加了一个捏合手势识别器,用它来关闭模态视图 Controller 。我是这样做的: UIPinchGestureRecognizer *closePinch = [[U
我不太确定为什么当我这样做时目标没有被调用: UIImage * imgSrc = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSU
我正在尝试创建一个 UIPinchGestureRecognizer,如果用户张开双指(将手指分开),它就会失败。我知道有一种非常简单的方法可以做到这一点,只需在操作方法中采用识别器的比例,如果它大于
我的 iOS 应用程序只有一个 View ,其中有一个 mapView。添加点击或长按识别器时,会正确调用事件。但不是捏事件... UIPinchGestureRecognizer *hand
我已经浏览过之前关于这个主题的主题,但我仍然无法找到解决方案。我已经研究了几天了。 我正在尝试在相机预览屏幕上使用 PinchGestureRecognizer。 但是,我收到了这个错误: Termi
我正在将 UIPinchGestureRecognizer 添加到显示图像的 scrollView。在紧要关头,我提出了一个新观点。 var pinch = UIPinchGestureRecogni
我想在使用捏合手势放大或缩小后返回原始图像大小。 我找到的类似答案是 How to get original image when we zoom in and zoom out the image
我有一个显示一些线条的简单图表控件。图表绘制涉及3个属性: 记录数 FirstVisibleIndex LastVisibleIndex 一切正常,图表在第一个和最后一个可见记录之间绘制得很好。现在我
问题:我在 View Controller 上有一个捏合手势识别器,我用它来缩放嵌套在 View Controller 内的图像。下面的变换工作正常,除了图像是从左上角而不是中心缩放的。我希望它从中心
我有一个通用二进制应用程序,目前正在开发该应用程序的 iPad 版本。 iPad 使用的是 uitabbarcontroller,在第二个选项卡上我有 6 个图像,添加 UIPinchGesture
在 Swift Gesture 函数中,映射到 UIPinchGestureRecognizer 的方法(下面代码的 panAction)在哪个线程上工作?它在主线程上工作吗? let pinchRe
我想知道是否有人知道 UIPinchGestureRecognizer 比例值是如何确定的,或者是否有我可以用来计算新比例值的公式? 我有一个应用程序,我将 UIPinchGestureRecogni
我在 UIMapView 中实现了手势识别器,正如此问题的已接受答案中所述:How to intercept touches events on a MKMapView or UIWebView ob
我正在使用 UIPinchGestureRecognizer 来检测捏合手势,例如: - (void) initPinchRecon { UIPinchGestureRecognizer *pinc
我在文档中没有找到关于如何为 UIPinchGestureRecognizer 或 UIRotationGestureRecognizer 指定触摸次数的方法。 我在任何地方发现它只能用两个手指,但根
我在我的应用程序中使用 UIPinchGestureRecognizer 来放大 View (是的,我不使用 UIScrollView 是有原因的)。当我用手指向外捏合时, View 会按预期放大,如
我想禁用缩小,我尝试通过 UIScrollView 上的 Storyboard 通过设置最小值来做到这一点,但没有什么区别。 let tap = UIPinchGestureRecognizer(ta
在 UIPinchGestureRecognizer 中如何获取参与触发手势的手指数量? 最佳答案 来自 UIPinchGestureRecognizer 类引用: UIPinchGestureRec
我如何使用 UIPinchGestureRecognizer 来使用 Transform 缩放 CALayer(基于现有的变换,层的当前状态)? - (IBAction)gesturePinch:(U
我是一名优秀的程序员,十分优秀!