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
  • 相关阅读:
    Java 泛型 泛型的约束与局限性
    Java 泛型 泛型方法
    Java 泛型 泛型数组
    Java 泛型 协变性、逆变性
    Java 泛型 协变式覆盖和泛型重载
    Java 泛型 泛型代码和虚拟机
    Insertion Sort List
    Remove Duplicates from Sorted List II
    String to Integer (atoi)
    SpringMvc源码入门
  • 原文地址:https://www.cnblogs.com/rhcad/p/2221372.html
Copyright © 2011-2022 走看看