<bdo id='PnyNb'></bdo><ul id='PnyNb'></ul>

    <small id='PnyNb'></small><noframes id='PnyNb'>

    1. <legend id='PnyNb'><style id='PnyNb'><dir id='PnyNb'><q id='PnyNb'></q></dir></style></legend>

        <i id='PnyNb'><tr id='PnyNb'><dt id='PnyNb'><q id='PnyNb'><span id='PnyNb'><b id='PnyNb'><form id='PnyNb'><ins id='PnyNb'></ins><ul id='PnyNb'></ul><sub id='PnyNb'></sub></form><legend id='PnyNb'></legend><bdo id='PnyNb'><pre id='PnyNb'><center id='PnyNb'></center></pre></bdo></b><th id='PnyNb'></th></span></q></dt></tr></i><div id='PnyNb'><tfoot id='PnyNb'></tfoot><dl id='PnyNb'><fieldset id='PnyNb'></fieldset></dl></div>
        <tfoot id='PnyNb'></tfoot>

      1. UIImageView 手势(缩放、旋转)问题

        UIImageView Gestures (Zoom, Rotate) Question(UIImageView 手势(缩放、旋转)问题)

          <legend id='2s5NV'><style id='2s5NV'><dir id='2s5NV'><q id='2s5NV'></q></dir></style></legend>

                <bdo id='2s5NV'></bdo><ul id='2s5NV'></ul>
              • <i id='2s5NV'><tr id='2s5NV'><dt id='2s5NV'><q id='2s5NV'><span id='2s5NV'><b id='2s5NV'><form id='2s5NV'><ins id='2s5NV'></ins><ul id='2s5NV'></ul><sub id='2s5NV'></sub></form><legend id='2s5NV'></legend><bdo id='2s5NV'><pre id='2s5NV'><center id='2s5NV'></center></pre></bdo></b><th id='2s5NV'></th></span></q></dt></tr></i><div id='2s5NV'><tfoot id='2s5NV'></tfoot><dl id='2s5NV'><fieldset id='2s5NV'></fieldset></dl></div>
                    <tbody id='2s5NV'></tbody>

                  <small id='2s5NV'></small><noframes id='2s5NV'>

                  <tfoot id='2s5NV'></tfoot>

                • 本文介绍了UIImageView 手势(缩放、旋转)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想对 UIImageView 进行 2 次缩放、旋转操作,我有 2 个问题:

                  I would like to make 2 operations to an UIImageView zoom, rotate, I have 2 problems:

                  A. 我为 ex 做了一个缩放操作.当我尝试进行旋转 UIImageView 设置为初始大小时,我想知道如何保持缩放后的 UIImageView 并从缩放后的图像进行旋转.

                  A. I make an operation for zoom for ex. and when I try to make rotation the UIImageView is set to initial size, I would like to know how to keep the zoomed UIImageView and make the rotation from the zoomed image.

                  B.我想将缩放操作与旋转结合起来,但我不知道如何实现:

                  B. I would like to combine the zoom operation with rotation and I don't know ho to implement this:

                  - (void)viewDidLoad 
                  {
                      foo = [[UIImageView alloc]initWithFrame:CGRectMake(100.0, 100.0, 600, 800.0)];
                      foo.userInteractionEnabled = YES;
                      foo.multipleTouchEnabled  = YES;
                      foo.image = [UIImage imageNamed:@"earth.jpg"];
                      foo.contentMode = UIViewContentModeScaleAspectFit;
                      foo.clipsToBounds = YES;
                      
                      [self.view addSubview:foo];
                  }
                  
                  //---pinch gesture--- 
                  UIPinchGestureRecognizer *pinchGesture =
                  [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
                  [foo addGestureRecognizer:pinchGesture]; 
                  [pinchGesture release];
                  
                  //---rotate gesture--- 
                  UIRotationGestureRecognizer *rotateGesture =
                  [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotateGesture:)];
                  [foo addGestureRecognizer:rotateGesture]; 
                  [rotateGesture release];
                  
                  //---handle pinch gesture--- 
                  -(IBAction) handlePinchGesture:(UIGestureRecognizer *) sender {
                      NSLog(@"Pinch");
                      CGFloat factor = [(UIPinchGestureRecognizer *) sender scale];
                      if (factor > 1) { 
                          //---zooming in--- 
                          sender.view.transform = CGAffineTransformMakeScale(
                                                                             lastScaleFactor + (factor-1),
                                                                             lastScaleFactor + (factor-1)); 
                      } 
                      else {
                          //---zooming out--- 
                          sender.view.transform = CGAffineTransformMakeScale(lastScaleFactor * factor, lastScaleFactor * factor);
                      }
                      if (sender.state == UIGestureRecognizerStateEnded) { 
                          if (factor > 1) {
                              lastScaleFactor += (factor-1); 
                          } else {
                              lastScaleFactor *= factor;
                          }
                      }
                  }
                  
                  //---handle rotate gesture--- 
                  -(IBAction) handleRotateGesture:(UIGestureRecognizer *) sender {
                      CGFloat rotation = [(UIRotationGestureRecognizer *) sender rotation]; 
                      CGAffineTransform transform = CGAffineTransformMakeRotation(rotation + netRotation); 
                      sender.view.transform = transform;
                      if (sender.state == UIGestureRecognizerStateEnded) { 
                          netRotation += rotation;
                      }
                  }
                  

                  谢谢

                  推荐答案

                  希望对你有所帮助,这就是我通常实现手势识别器的方式:

                  Hope this can be helpful to you, that's how I usually implement gesture recognizers:

                  UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotatePiece:)];
                  [piece addGestureRecognizer:rotationGesture];
                  [rotationGesture release];
                  
                  UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePiece:)];
                  [pinchGesture setDelegate:self];
                  [piece addGestureRecognizer:pinchGesture];
                  [pinchGesture release];
                  

                  Rotate 方法:应用后将手势识别器的旋转重置为 0,因此下一个回调是当前旋转的增量

                  Rotate method: Reset the gesture recognizer's rotation to 0 after applying so the next callback is a delta from the current rotation

                  - (void)rotatePiece:(UIRotationGestureRecognizer *)gestureRecognizer {
                      [self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
                  
                      if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
                          [gestureRecognizer view].transform = CGAffineTransformRotate([[gestureRecognizer view] transform], [gestureRecognizer rotation]);
                          [gestureRecognizer setRotation:0];
                      }
                  }
                  

                  Scale 方法,最后在应用后将手势识别器的比例重置为 1,因此下一个回调是当前比例的增量

                  Scale Method, at the end reset the gesture recognizer's scale to 1 after applying so the next callback is a delta from the current scale

                  - (void)scalePiece:(UIPinchGestureRecognizer *)gestureRecognizer {
                  [self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
                  
                      if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
                          [gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);
                          [gestureRecognizer setScale:1];
                      }
                  }
                  

                  确保特定视图上的捏合、平移和旋转手势识别器都可以同时识别,以防止其他手势识别器同时识别

                  Than ensure that the pinch, pan and rotate gesture recognizers on a particular view can all recognize simultaneously prevent other gesture recognizers from recognizing simultaneously

                  - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
                  // if the gesture recognizers are on different views, don't allow simultaneous recognition
                  if (gestureRecognizer.view != otherGestureRecognizer.view)
                      return NO;
                  
                  // if either of the gesture recognizers is the long press, don't allow simultaneous recognition
                  if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] || [otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]])
                      return NO;
                  
                      return YES;
                  }
                  

                  相对于图层的锚点应用缩放和旋转变换此方法在用户手指之间移动手势识别器视图的锚点

                  Scale and rotation transforms are applied relative to the layer's anchor point this method moves a gesture recognizer's view's anchor point between the user's fingers

                  - (void)adjustAnchorPointForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
                      if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
                          UIView *piece = gestureRecognizer.view;
                          CGPoint locationInView = [gestureRecognizer locationInView:piece];
                          CGPoint locationInSuperview = [gestureRecognizer locationInView:piece.superview];
                  
                          piece.layer.anchorPoint = CGPointMake(locationInView.x / piece.bounds.size.width, locationInView.y / piece.bounds.size.height);
                          piece.center = locationInSuperview;
                      }
                  }
                  

                  这篇关于UIImageView 手势(缩放、旋转)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Responsive website on iPhone - unwanted white space on rotate from landscape to portrait(iPhone上的响应式网站-从横向旋转到纵向时不需要的空白)
                  How to rotate an image 90 degrees on iOS?(如何在 iOS 上将图像旋转 90 度?)
                  How to capture current view screenshot and reuse in code? (iPhone SDK)(如何捕获当前视图屏幕截图并在代码中重用?(iPhone SDK))
                  iOS 6 shouldAutorotate: is NOT being called(iOS 6 shouldAutorotate: 没有被调用)
                  What is the PastryKit Framework?(PastryKit 框架是什么?)
                  Undefined symbols for architecture armv7: quot;_SCNetworkReachabilityCreateWithAddressquot;(架构 armv7 的未定义符号:“_SCNetworkReachabilityCreateWithAddress)
                        <tbody id='hTCli'></tbody>
                      <legend id='hTCli'><style id='hTCli'><dir id='hTCli'><q id='hTCli'></q></dir></style></legend>

                        <small id='hTCli'></small><noframes id='hTCli'>

                          <i id='hTCli'><tr id='hTCli'><dt id='hTCli'><q id='hTCli'><span id='hTCli'><b id='hTCli'><form id='hTCli'><ins id='hTCli'></ins><ul id='hTCli'></ul><sub id='hTCli'></sub></form><legend id='hTCli'></legend><bdo id='hTCli'><pre id='hTCli'><center id='hTCli'></center></pre></bdo></b><th id='hTCli'></th></span></q></dt></tr></i><div id='hTCli'><tfoot id='hTCli'></tfoot><dl id='hTCli'><fieldset id='hTCli'></fieldset></dl></div>
                            <bdo id='hTCli'></bdo><ul id='hTCli'></ul>
                            <tfoot id='hTCli'></tfoot>