Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS无法通过按按钮对象移动视图_Ios_View_Touchesmoved - Fatal编程技术网

iOS无法通过按按钮对象移动视图

iOS无法通过按按钮对象移动视图,ios,view,touchesmoved,Ios,View,Touchesmoved,我对视图对象有问题。如果触摸按钮A或B并移动,我想移动父视图。 但当按下按钮时,它应该像往常一样工作-只是(iAction)ABtnPressed:(id)发送器功能 ---------------------- | | | Parent View | | | | | | | |

我对视图对象有问题。如果触摸按钮A或B并移动,我想移动父视图。 但当按下按钮时,它应该像往常一样工作-只是(iAction)ABtnPressed:(id)发送器功能

 ----------------------
 |                    |
 |  Parent View       |
 |                    |
 |                    |
 |                    |
 |                    |
 |  ________________  |
 | | Another view   | |
 | | ------  ------ | |
 | | | A  |  |  B | | |
 | | ------  ------ | |
 | |________________| |
 |____________________|
我是如何做到的:

-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件 { NSSet*AllTouchs=[event AllTouchs]; UITouch*touch=[[AllTouchs AllObject]对象索引: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);
    } 

请帮助我,我如何解决这个问题。我刚刚开始为iOS开发。

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


祝你好运

我已回复了你的邮件。