zoukankan      html  css  js  c++  java
  • Quartz 2D 练习2多点触摸画圈

    总结:

    1、在iTouch4上运行检测到的触摸点数最大是5,即只允许5个手指在屏幕上滑动

    2、视图支持多点触摸:isMultipleTouchEnabled返回YES,或者设置 multipleTouchEnabled属性为YES

    3、要将多个CGPoint点添加到NSMutableArray,使用 NSStringFromCGPoint 函数,使用 CGPointFromString 从数组中取出坐标

    TouchesView.h

    #import <UIKit/UIKit.h>
    
    
    @interface TouchesView : UIView {
        NSMutableArray* _points;
    }
    
    - (void)showPoints:(NSSet *)touches;
    
    @end

    TouchesView.m

    #import "TouchesView.h"
    
    
    @implementation TouchesView
    
    - (id)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
        _points = [[NSMutableArray alloc] init];
        return self;
    }
    
    - (void)dealloc
    {
        [_points release];
        [super dealloc];
    }
    
    - (BOOL)isMultipleTouchEnabled
    {
        return YES;
    }
    
    - (void)drawRect:(CGRect)rect
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        
        for (NSString* ptstr in _points) {
            CGPoint pt = CGPointFromString(ptstr);
            CGContextStrokeEllipseInRect(context, CGRectMake(pt.x - 40, pt.y - 40, 80, 80));
        }
    }
    
    - (void)showPoints:(NSSet *)touches
    {
        [_points removeAllObjects];
        
        for (UITouch* touch in touches) {
            CGPoint pt = [touch locationInView:self];
            [_points addObject: NSStringFromCGPoint(pt)];
        }
        NSLog(@"Touches count: %d", touches.count);
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        assert(_points != Nil);
        [self showPoints: touches];
        [self setNeedsDisplay];
    }
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [self showPoints: touches];
        [self setNeedsDisplay];
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        //[_points removeAllObjects];
        [self setNeedsDisplay];
    }
    
    @end
  • 相关阅读:
    并发工具类的使用 CountDownLatch,CyclicBarrier,Semaphore,Exchanger
    多线程按顺序执行3个方法
    读写锁事例
    使用AQS自定义重入锁
    java 几种锁实现
    Nginx 安装
    Windows 安装mysql
    day--14前端(HTML、CSS)
    day13--开发堡垒机
    day12--python操作mysql
  • 原文地址:https://www.cnblogs.com/rhcad/p/2221372.html
Copyright © 2011-2022 走看看