Button Initialization
- -(Void) viewDidLoad
- {
- [Super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- Self. btn = [UIButton buttonWithType: UIButtonTypeRoundedRect];
- Self. btn. frame = CGRectMake (10, 10, 50, 50 );
- [Self. btn setTitle: @ "Touch" forState: UIControlStateNormal];
- [Self. btn addTarget: self action: @ selector (dragMoving: withEvent:) forControlEvents: UIControlEventTouchDragInside];
- [Self. btn addTarget: self action: @ selector (doClick :) forControlEvents: UIControlEventTouchUpInside];
- Self. a = 0;
- [Self. view addSubview: self. btn];
- }
Click Method
- -(void)doClick:(UIButton*)sender
- {
- if (self.a==0)
- {
- NSLog(@"1111");
- }
- self.a=0;
- }
Drag Method
- - (void) dragMoving: (UIButton *) c withEvent:ev
- {
- self.a=1;
- c.center = [[[ev allTouches] anyObject] locationInView:self.view];
- NSLog(@"%f,,,%f",c.center.x,c.center.y);
- }