繪圖、手勢綜合App

杭城小劉發表於2019-03-01

##手勢的一些注意事項

對於 UITapGestureRecognizer 來說我們一般需要知道該點選手勢在螢幕中的位置 (locationInView:self)

對於 UIPanGestureRecognizer 來說我們一般需要知道我們的滑動手勢移動了多少距離 (translationInView:pan)

-(void) pan: (UIPanGestureRecognizer * ) pan {

    CGPoint transP = [pan translationInView: pan.view]; //$1 = (x = 0.73990527317289434, y = 0)

    CGPoint pont1 = [pan locationInView: self]; //$2 = (x = 198.16665649414063, y = 342.33332824707031)

    CGPoint pont2 = [pan locationInView: self.imageV]; //$3 = (x = 198.12057060663793, y = 342.61609831987914)

    pan.view.transform = CGAffineTransformTranslate(pan.view.transform, transP.x, transP.y);
    //復位
    [pan setTranslation: CGPointZero inView: pan.view];

}

複製程式碼
[UIView animateWithDuration: 0.25 animations: ^ {
        self.imageView.alpha = 0;
    }completion: ^ (BOOL finished){
        self.imageView.alpha = 1;

        UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0);
        CGContextRef ctx = UIGraphicsGetCurrentContext();

        [self.layer renderInContext: ctx];

        UIImage * imageGot = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        [self.imageView removeFromSuperview];

        if (self.delegate && [self.delegate respondsToSelector: @selector(handleImageView: didOperatedImage: )]){
            [self.delegate handleImageView: self didOperatedImage: imageGot];
        }
    }
];

複製程式碼

接下來來一個iOS圖形繪製、旋轉、長按、縮放、滑動等綜合手勢的一個 畫圖 專案

畫圖App效果圖

##** 程式碼地址

相關文章