Xcode iOS push down button and drag then up on a second button

后端 未结 5 1518
悲&欢浪女
悲&欢浪女 2021-01-15 20:06

Lets say I wan\'t to add 1 to an integer. This will only be done when I push down on a UIButton and then release my finger on another UIButton.

5条回答
  •  一生所求
    2021-01-15 20:46

    // Create a button, add targets

    UIButton *cloudButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [cloudButton setImage:[UIImage imageNamed:@"notification_add.png"] forState:UIControlStateNormal];
            [cloudButton setFrame:CGRectMake(0, 0, 30, 30)];
            [cloudButton addTarget:self action:@selector(dragBegan:withEvent: )
               forControlEvents: UIControlEventTouchDown];
            [cloudButton addTarget:self action:@selector(dragMoving:withEvent: )
               forControlEvents: UIControlEventTouchDragInside | UIControlEventTouchDragOutside];
            [cloudButton addTarget:self action:@selector(dragEnded:withEvent: )
               forControlEvents: UIControlEventTouchUpInside |
             UIControlEventTouchUpOutside];
    
            [self.view addSubview:cloudButton];
    

    //event methods

    - (void) dragBegan: (UIControl *) c withEvent:ev
    {
        NSLog(@"dragBegan......");
    }
    
    - (void) dragMoving: (UIControl *) c withEvent:ev
    {
        NSLog(@"dragMoving..............");
    }
    - (void) dragEnded: (UIControl *) c withEvent:ev
    {
        NSLog(@"dragEnded..............");
    }
    

提交回复
热议问题