博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IOS拖动
阅读量:4507 次
发布时间:2019-06-08

本文共 1065 字,大约阅读时间需要 3 分钟。

http://blog.csdn.net/mamong/article/details/20831899

代码资源

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIButton *btn;

@end

@implementation ViewController

@synthesize btn;

- (void)viewDidLoad

{
[super viewDidLoad];
self.btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.btn.frame = CGRectMake(10, 10, 50, 50);

[self.btn setTitle:@"触摸" forState:UIControlStateNormal];

[self.btn setTitle:@"移动" forState:UIControlEventTouchDown];
[self.btn addTarget:self action:@selector(dragMoving:withEvent: )forControlEvents: UIControlEventTouchDragInside];
[self.btn addTarget:self action:@selector(dragEnded:withEvent: )forControlEvents: UIControlEventTouchUpInside |
UIControlEventTouchUpOutside];
[self.view addSubview:self.btn];
}

- (void) dragMoving: (UIControl *) c withEvent:ev
{
c.center = [[[ev allTouches] anyObject] locationInView:self.view];
}

- (void) dragEnded: (UIControl *) c withEvent:ev

{
c.center = [[[ev allTouches] anyObject] locationInView:self.view];
}

@end

转载于:https://www.cnblogs.com/wcLT/p/4198882.html

你可能感兴趣的文章
Visual Studio中的快捷键
查看>>
Mac下显示和隐藏“隐藏文件”
查看>>
Chessboard POJ - 2446(最大流 || 匹配)
查看>>
Warning: Cannot modify header information原因及解决方案
查看>>
Python ConfigParser模块
查看>>
程序员的学习和积累
查看>>
.net实现支付宝在线支付
查看>>
centos7 swoole 三步搞定全部
查看>>
noip2014day1题解
查看>>
Excel:一些方法的理解
查看>>
【转】在RHEL上升级Python
查看>>
java:环境变量设置
查看>>
Servlet的学习之Response响应对象(3)
查看>>
基础知识回顾——上下文管理器
查看>>
ARM(RISC)和x86(CISC)的技术差异
查看>>
第3章 对象基础
查看>>
文件压缩与解压缩
查看>>
android 搜索自动匹配关键字并且标红
查看>>
Android ViewPager使用详解
查看>>
python爬虫之scrapy的pipeline的使用
查看>>