标签: touchesbegan

如何处理 SKShapeNode 子类中的触摸?

我正在寻找一种简单的方法来处理 SKShapeNode 子类中的触摸。为此,我尝试使用touchesBegan,但它不起作用..

class Shape: SKShapeNode {


convenience init(rectOfSize: CGSize, colorOfRectangle rectColor: UIColor) {

    self.init()

    self.init(rectOfSize: rectOfSize)
    self.fillColor = rectColor
    self.position = CGPointMake(rectOfSize.width, rectOfSize.height)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    print("touch")   
}
}
Run Code Online (Sandbox Code Playgroud)

touchesbegan ios sprite-kit skshapenode swift

2
推荐指数
1
解决办法
321
查看次数

Swift 中令人困惑的反向触摸事件

在我的函数中

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
    for touch in touches{
        let touchLocation = touch.location(in: self.view)
        print("X: \(touchLocation.x) Y: \(touchLocation.y)")
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到反转的 Y 值。如果我点击顶部,我会得到 ~0 值,如果我点击底部,我会得到高价值。这使我的精灵在错误的 Y 方向上移动。

但是,如果我删除 self.view 中的“.view”,它会正常工作。有谁知道为什么当我使用 self.view 时它会反转?

touchesbegan ios sprite-kit swift

2
推荐指数
1
解决办法
185
查看次数

UIViewController子类未收到触摸开始iphone ipad

因此,我将UIViewController子类化,在笔尖中有一个UIView,并在其中有一个tableview。据我了解,UIViewController和UIView都是UIResponder的子类,因此它们应该接收-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event方法。

但是,事实并非如此,并且我的视图控制器子类未接收该方法。如果可以的话,我真的不希望将UIView子类化。

我正在尝试实现这一点,但我的

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [textfield resignFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)

没有接到电话。

iphone subclass uiviewcontroller ipad touchesbegan

1
推荐指数
1
解决办法
1万
查看次数

点击UIButton时手指的iOS x坐标

我有一个UIButton.当用户点击所述按钮时,如何获得手指的x坐标.我认为它将涉及touchesBegan,但如果按钮上出现"touchesBegan",我怎么才能获得值?如果有一种方法(不仅监视按钮的x,y,宽度和高度,并检查我的触摸是否在该区域)我将需要禁用按钮的用户交互,以便代码可以处理它而不是内置xib的东西.谢谢!

location button touch touchesbegan ios

1
推荐指数
1
解决办法
1745
查看次数

方法不会覆盖它的超类中的任何方法

当我收到此错误时,我正在尝试创建一个新的覆盖功能:方法不会覆盖它的超类中的任何方法

我已经尝试删除覆盖部分,但这只会给我一个错误.

override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {

    let touch : UITouch! = touches.anyObject() as! UITouch

    location = touch.locationInView(self.view)

    person.center = location
}

override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {

    let touch : UITouch! = touches.anyObject() as! UITouch

    location = touch.locationInView(self.view)

    person.center = location

}
Run Code Online (Sandbox Code Playgroud)

touchesmoved touchesbegan swift

1
推荐指数
1
解决办法
3328
查看次数

使用SpriteKit一次移动多个节点

我有一个游戏,有3个SKSpriteNodes用户可以使用touchesBegan和移动touchesMoved.但是,当用户移动nodeA并通过另一个被调用的节点时nodeB,nodeB跟随nodeA等等.

我创建了一个数组SKSpriteNodes并使用a for-loop来简化生活.

 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {


        let nodes = [nodeA, nodeB, nodeC]

        for touch in touches {

            let location = touch.location(in: self)

            for node in nodes {

                if node!.contains(location) {

                    node!.position = location
                }

            }


        }

    }
Run Code Online (Sandbox Code Playgroud)

一切正常,除非在nodeA移动和交叉路径时nodeB,nodeB遵循nodeA.

我怎样才能让这个当用户移动nodeAnodeA通过传递nodeBnodeB将不遵循nodeA.

touchesmoved touchesbegan sprite-kit

1
推荐指数
1
解决办法
506
查看次数

在UIImageView中没有检测到touchesbegan

您好我有5张图片浏览,所有这些都是导航栏中的子视图.我想从每个imageview获得tapcounts,所以我认为我必须使用touchesBegan方法.但实际上,在每个图像视图中都没有检测到触摸事件.确切地说,touchesBegan在工具栏中检测到.层次结构是:

UIViewController - > UIToolbar

             -> UINavigationBar -> UIImageView
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
int indexSegment = _docSegmentedControl.selectedSegmentIndex;


CGRect frameTouch;

if (indexSegment == 0) {
    frameTouch = frame;
}else if (indexSegment == 1) {
    frameTouch = frame1;
}else if (indexSegment == 2) {
    frameTouch = frame2;
}else if (indexSegment == 3) {
    frameTouch = frame3;
}else if (indexSegment == 4) {
    frameTouch = frame4;
}


UITouch *touch = [touches anyObject];

//--image 0--
CGPoint gestureStartPoint0 = [touch locationInView:imageView];
if (CGRectContainsPoint(frame, gestureStartPoint0)) …
Run Code Online (Sandbox Code Playgroud)

uinavigationbar uitoolbar uiimageview ipad touchesbegan

0
推荐指数
1
解决办法
2069
查看次数

touchesBegan函数从不输入

我正在尝试为我的应用弹出一个弹出窗口。到目前为止,弹出窗口以固定的坐标弹出,我试图将其弹出到用户点击的位置。这就是我所拥有的:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    print("touchesbegan")
    for touch in touches{
        //Handle touch
        let location = touch.locationInView(self.view)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)

        let vc = storyboard.instantiateViewControllerWithIdentifier("ColonyPopoverController") as! ColonyPopoverController
        vc.modalPresentationStyle = .Popover
        vc.preferredContentSize = CGSizeMake(200, 150)

        if let popoverController = vc.popoverPresentationController {
            popoverController.delegate = self
            popoverController.sourceRect = CGRectMake(location.x, location.y, 20, 10)
            popoverController.sourceView = self.view
            self.presentViewController(vc, animated: true, completion: nil)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我注意到当我点击模拟器时,打印语句永远不会打印。

我认为interaction并已multi-touch启用。我知道这种方法很好用,因为我也将其与Google Maps集成在一起,因此当我点击时,会出现一个google pin:

func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) …
Run Code Online (Sandbox Code Playgroud)

touchesbegan gmsmapview swift

0
推荐指数
1
解决办法
7682
查看次数

在Xcode 6中触摸位置和触摸开始[Obj-C - > Swift]

我在创建函数"touchesBegan"时遇到问题,然后创建一个包含x和y坐标的UIPoint和UITouch常量或变量.我在Objective-C中有我想要的确切代码,但我不知道它在Swift中的含义是什么.这是我想要基本上转换成Swift代码的Objective-C代码...注意:这是一个单视图应用程序,而不是游戏...提前感谢.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];

    if (point.x < 160) {
        var = 10;
    }
    else{
        var = 20;
    }

}
Run Code Online (Sandbox Code Playgroud)

xcode objective-c touchesbegan ios swift

-4
推荐指数
2
解决办法
7907
查看次数