资源描述:
《《iOS高级应用开发技术》实验报告九详细答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验名称:手势识别计算机科学学院2015级班指导老师:李贵洋实验成绩:实验九手势识别一.实验目的及要求理解并掌握iOS多点手势识别的相关技术;二.实验内容(1)分別采用代码随机位置大小生成和直接拖拽的方式产生多个视图;(2)给视图加上阴影(layer);(3)可全部清空子视图;(4)视图支持手势(pan移动、tap删除、pinch缩放、rotation旋转);三.实验主要流程、基本操作或核心代码、算法片段(该部分如不够填写,请另加附页)•代码:ViewController.swift://text9////Createdbywuon2017/11
2、/18.//Copyright©2017年2015110445.Allrightsreserved.//importUIKitclassViewControl1er:UTViewControl1er{overridefuncviewDidLoad(){super.viewDidLoad()//Doanyadditionalsetupafterloadingtheview,typicallyfromanib.title="CustomView"self,view.backgroundColor=UlColor.whiteletaddBtn二UIBa
3、rButtonltem(title:〃添加style:style:•plain,target:self,action:#selector(addView))letmoveBtn=UIBarButtonltem(title:"移动•plain,target:self,action:ftselector(moveViews))moveBtn]letclcarBtn=UIBarButtonltcm(title:"清空style:•plain,target:self,action:ftselector(clearView))self.navigation
4、item・leftBarButtonlteni=clearBtn@objcfuncaddView(){letmaxWidth:CGFloat=150letx=CGFloat(arc4random()%UInt32(self,view.bounds.width))lety=CGF1oat(arc4random()%UTnt32(self.view.bounds.height-40))+40letpoint=CGPoint(x:x,y:y)letwidth二CGFloat(aredrandom()%UInt32(maxWidth))letheight
5、二CGFloat(arc4random()%UTnt32(maxWidth))letsize=CGSize(width:width,height:height)letview二MyView(frame:CGRect(origin:point,size:size))iself,vicw.addSubvicw(vicw)j©objcfuncclearViewO{)self•view.subviews,map{$0.removeFromSuperview()@objcfuncmoveViews(){self,view.subviews,map{(vie
6、w)inletx二CGFloat(arcdrandom()%UInt32(seIf.view,bounds.width))lety=CGFloat(arc4random()%UInt32(seIf.view,bounds,height-40))+40letpoint二CGPoint(x:x,y:y)UlView.animate(withDuration:3,animations:view.centerpoint})overridefuncdidReceiveMemoryWarning(){super.didReceiveMemoryWarning
7、()//Disposeofanyresourcesthatcanberecreatcd.MyView.swift:////MyView.swift//text9////Createdbywuon2017/11/18.//Copyright©2017年2015110445.Allrightsreserved.//importUIKitclassMyView:UlView{overridefuncdraw(_rect:CGRect){:UIBezierPath(rect:rect)letviewRect二letredColor二:CGFloat(Fl
8、oat(arc4random()%255)/255)letgreenColor=CGFloat(Float(arc4random()%2