中和软件技术培训

上海中和软件公司培训专用博客

UIView TouchBegan

UIView使用多点触摸的代码


//
//  ViewController.swift
//  Canvas
//
//  Created by Hu on 2017/9/22.
//  Copyright © 2017年 Hu. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        // loop through the touches
        for touch in touches {
            
            // Set the Center of the Circle
            let circleCenter = touch.location(in: view)
            
            // Set a random Circle Radius
            let circleWidth = CGFloat(25 + (arc4random() % 50))
            let circleHeight = circleWidth
            
            // Create a new CircleView
            let Rect = CGRect.init(x: circleCenter.x - circleHeight/2, y: circleCenter.y - circleHeight/2, width: circleWidth, height: circleHeight)
            let circleView = CircleView(frame:Rect)
            circleView.backgroundColor = .white
            view.addSubview(circleView)
        }
    }
   
    
}

博文最后更新时间:


评论

  • 暂无评论

发表评论

博客统计

访问量:12712

博文总数:13 评论总数:6

原创12 翻译0 转载1