iOS按下按钮对象无法移动VIEW

时间:2014-05-03 09:47:17

标签: ios view touchesmoved

我遇到了VIEW Objects的问题。如果触摸在按钮A或B上并移动,我想移动父视图。 但是当按下按钮时它应该像往常一样 - 只是(IBAction)ABtnPressed:(id)发送者功能。

 ----------------------
 |                    |
 |  Parent View       |
 |                    |
 |                    |
 |                    |
 |                    |
 |  ________________  |
 | | Another view   | |
 | | ------  ------ | |
 | | | A  |  |  B | | |
 | | ------  ------ | |
 | |________________| |
 |____________________|

我是怎么做到的:  
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSSet *allTouches = [event allTouches]; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint touchLocation = [touch locationInView:self.view];

    if (touch.view == AnotherView) // It's work properly
    {
          ParentView.center = CGPointMake(ParentView.center.x, touchLocation.y);
    }   

    if (touch.view == AButton) // It's **NOT** work properly
    {
          ParentView.center = CGPointMake(ParentView.center.x, touchLocation.y);
    } 

if (touch.view == AnotherView) // It's work properly { ParentView.center = CGPointMake(ParentView.center.x, touchLocation.y); } if (touch.view == AButton) // It's **NOT** work properly { ParentView.center = CGPointMake(ParentView.center.x, touchLocation.y); } 请帮帮我,我怎么解决这个问题。我刚开始为iOS开发。

1 个答案:

答案 0 :(得分:0)

因为UIButton有自己的触摸事件,所以它不会听普通的触摸代表,你必须使用UIGestureRecognisers,添加两个按钮并像普通选择器一样查看

祝你好运