移动uiView 缩放uiView+一个View实现不同子view的功能
2013-12-09 22:40
555 查看
//移动uiView UITouch *touch1=[touches anyObject]; CGPoint onePoint=[touch1 locationInView:self.window]; CGPoint newOnePoint=[touch1 previousLocationInView:self.window]; CGFloat distanceX=onePoint.x-newOnePoint.x; CGFloat distanceY=onePoint.y-newOnePoint.y; self.center=CGPointMake(self.center.x+distanceX,self.center.y+distanceY); //显示uiview移动的方向 if (onePoint.x<newOnePoint.x) { NSLog(@"向左移动"); }else if (onePoint.x>newOnePoint.x){ NSLog(@"向右移动"); }else if (onePoint.y>newOnePoint.y){ NSLog(@"向下移动"); }else if(onePoint.y<newOnePoint.y){ NSLog(@"向上移动"); } //缩放uiView if (touches.count>=2) { //获取每一个touches的x,y值 NSArray *array=[touches allObjects]; CGPoint point1=[[array objectAtIndex:0] locationInView:self]; CGPoint point2=[[array objectAtIndex:1] locationInView:self]; CGPoint newPoint1=[[array objectAtIndex:0] previousLocationInView:self]; CGPoint newPoint2=[[array objectAtIndex:1] previousLocationInView:self]; //判断是不是同一个点并根据center缩放大小 if (point1.x!=point2.x && point1.y!=point2.y) { CGFloat num=sqrt(((point2.x-point1.x)*(point2.x-point1.x))+((point2.y-point1.y)*(point2.y-point1.y))); CGFloat newNum=sqrt(((newPoint2.x-newPoint1.x)*(newPoint2.x-newPoint1.x))+((newPoint2.y-newPoint1.y)*(newPoint2.y-newPoint1.y))); self.bounds=CGRectMake(0, 0,self.bounds.size.width*(num/newNum),self.bounds.size.height*(num/newNum)); } } RootViewController DragView *dragView=[[DragView alloc]initWithFrame:CGRectMake(30, 30, 130, 140)]; dragView.backgroundColor=[UIColor redColor]; [self.view addSubview:dragView]; //4.创建一个TouchView(kongjian),创建TouchView的3个实例,touchView1 被点击之后,touchView换背景颜色.tuochView2被点击后换位置(随机cengter),touchView3被点击后,打印一句话 if ([self viewWithTag:100]) { self.backgroundColor=[UIColor colorWithRed:arc4random()%256/255.0 green: arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1]; }else if ([self viewWithTag:200]) { self.center=CGPointMake(arc4random()%100+30, arc4random()%400+40); }else if ([self viewWithTag:300]) { NSLog(@"minamima"); } RootViewContrller文件 TouchView *touchViewColor=[[TouchView alloc]initWithFrame:CGRectMake(30, 30, 60, 30)]; touchViewColor.backgroundColor=[UIColor redColor]; [self.view addSubview:touchViewColor]; touchViewColor.tag=100; TouchView *touchViewText=[[TouchView alloc]initWithFrame:CGRectMake(30, 200, 60, 30)]; touchViewText.backgroundColor=[UIColor redColor]; [self.view addSubview:touchViewText]; touchViewText.tag=300; TouchView *touchViewCenter=[[TouchView alloc]initWithFrame:CGRectMake(30, 120, 60, 30)]; touchViewCenter.backgroundColor=[UIColor redColor]; [self.view addSubview:touchViewCenter]; touchViewCenter.tag=200;
相关文章推荐
- 【IOS】扩展UIImageViewEx实现:手势移动,旋转,缩放(附带一个收缩的文字标签功能)
- 【IOS】扩展UIImageViewEx实现:手势移动,旋转,缩放(附带一个收缩的文字标签功能)
- 【IOS】扩展UIImageViewEx实现:手势移动,旋转,缩放(附带一个收缩的文字标签功能)
- 【IOS】扩展UIImageViewEx实现:手势移动,旋转,缩放(附带一个收缩的文字标签功能)
- 【IOS】扩展UIImageViewEx实现:手势移动,旋转,缩放(附带一个收缩的文字标签功能)
- Android实战技巧:用TextView实现Rich Text---在同一个TextView中设置不同的字体风格
- 一个TextView实现不同部分添加不同样式
- UIday1002:UITableView 2 用UITableView实现通讯录cell简单的数据移动、删除、添加功能
- [Phonegap+Sencha Touch] 移动开发61 使用 URL Schemes实现一个App启动另一个App的功能
- Android实战技巧:用TextView实现Rich Text---在同一个TextView中设置不同的字体风格
- 实现一个类似于CCTableView的功能的代码
- RecyclerView加载不同item并实现其item点击事件,实现添加常用应用的功能
- Android实战技巧:用TextView实现Rich Text---在同一个TextView中设置不同的字体风格
- Android开发 自定义ViewGroup 实现微信九格图功能(图片不同排布不同) 和 一种图片点击变暗效果
- 教你实现一个具备展开折叠功能的TextView(个人感觉github上的内容不错!https://github.com/r17171709/android_demo)
- 如何用数据驱动实现通用化巡检APP(如何一个界面里添加多个点击拍照按钮并显示在不同的imageview里)
- 自定义一个view,并实现最简单的手势识别功能(下)
- ndroid setContentView 实现同一个activity下不同view的切换
- textfield/textview的子类,实现功能:几种不同类型的最大输入字符串字数限制,剩余可输入字符数,emoji表情过滤
- Android5.0 共享元素 实现不同页面的同一个View的切换效果