首页 > 移动平台 > 详细

IOS拖动

时间:2015-01-02 22:20:29      阅读:362      评论:0      收藏:0      [点我收藏+]

#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

IOS拖动

原文:http://www.cnblogs.com/wcLT/p/4198882.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!