查看: 2178|回复: 0

[IOS开发教程] 开发绘图、手势综合App注意点

发表于 2018-4-13 08:00:05

手势的一些注意事项

对于 UITapGestureRecognizer 来说我们一般需要知道该点击手势在屏幕中的位置 (locationInView:self)

对于 UIPanGestureRecognizer 来说我们一般需要知道我们的滑动手势移动了多少距离 (translationInView:pan)

  1. -(void) pan: (UIPanGestureRecognizer * ) pan {
  2. CGPoint transP = [pan translationInView: pan.view]; //$1 = (x = 0.73990527317289434, y = 0)
  3. CGPoint pont1 = [pan locationInView: self]; //$2 = (x = 198.16665649414063, y = 342.33332824707031)
  4. CGPoint pont2 = [pan locationInView: self.imageV]; //$3 = (x = 198.12057060663793, y = 342.61609831987914)
  5. pan.view.transform = CGAffineTransformTranslate(pan.view.transform, transP.x, transP.y);
  6. //复位
  7. [pan setTranslation: CGPointZero inView: pan.view];
  8. }
复制代码
  1. [UIView animateWithDuration: 0.25 animations: ^ {
  2. self.imageView.alpha = 0;
  3. }completion: ^ (BOOL finished){
  4. self.imageView.alpha = 1;
  5. UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0);
  6. CGContextRef ctx = UIGraphicsGetCurrentContext();
  7. [self.layer renderInContext: ctx];
  8. UIImage * imageGot = UIGraphicsGetImageFromCurrentImageContext();
  9. UIGraphicsEndImageContext();
  10. [self.imageView removeFromSuperview];
  11. if (self.delegate && [self.delegate respondsToSelector: @selector(handleImageView: didOperatedImage: )]){
  12. [self.delegate handleImageView: self didOperatedImage: imageGot];
  13. }
  14. }
  15. ];
复制代码

接下来来一个iOS图形绘制、旋转、长按、缩放、滑动等综合手势的一个 画图 项目

源码地址:https://github.com/FantasticLBP/BlogDemos/tree/master/

以上就是本次我们分享的全部内容,感谢你对程序员之家的支持。



回复

使用道具 举报