简体   繁体   English

如何制作启用多点触控的ios应用

[英]how to make multi touch enabled ios app

I have made an app and i want to make it multi touch compatible. 我做了一个应用程序,我想使其与多点触控兼容。 i have tried looking around but the answers aren't specific to mine. 我曾尝试环顾四周,但答案并非特定于我。 Here is what i do: 这是我的工作:

1) My coding: 1)我的编码:

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

[self touchesMoved:touches withEvent:event];
if (gameState == kGameStatePaused) {(gameState = kGameStateRunning);}
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if(gameState == kGameStateRunning) {

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    if(location.x > 400) {

        CGPoint yLocation = CGPointMake(playerPaddle.center.x, location.y);
        playerPaddle.center = yLocation;
    }

    if (gameStyle == kGameStyleTwoP) {
        if(location.x < 100) {

            CGPoint yLocation2 = CGPointMake(computerPaddle.center.x, location.y);
            computerPaddle.center = yLocation2;
        }
    }
}

2) I have gone onto Interface Builder and checked the box for multitouch enabled 2)我已经进入Interface Builder并选中了启用多点触摸的复选框

3) I build and run my app and it opens properly and when i go to test the multitouch i hold "option key" and click and move the mouse 3)我构建并运行我的应用程序,它会正确打开,当我去测试多点触控时,我按住“选项键”并单击并移动鼠标

4) (i am trying to make computerPaddle and playerPaddle both move) but only one of the works at a time 4)(我正在尝试使computerPaddle和playerPaddle都移动),但一次只能进行一项操作

I have to tried to fix it but i can't understand where i am going wrong. 我必须尝试修复它,但我不明白我要去哪里。

Any help is useful. 任何帮助都是有用的。 THX. 谢谢。

There is a property named multipleTouchEnabled on the UIView that you can set to YES to enable it (defaults NO). UIView上有一个名为multipleTouchEnabled的属性,您可以将其设置为YES以启用它(默认为NO)。

Also, you should loop to treat all touches in the touches set that you receive in touchesMoved . 同样,您应该循环处理在touchesMoved收到的touches集中的所有触摸。

look this line 看这条线

UITouch *touch = [[event allTouches] anyObject];

you only take one touch and ignore rest and thats why only one thing can move 您只需要轻轻一按,就忽略休息,这就是为什么只有一件事可以移动的原因

so replace with a for loop should fix the problem 所以用for循环替换应该可以解决问题

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if(gameState == kGameStateRunning) {

    for (UITouch *touch in [event allTouches]) {
    CGPoint location = [touch locationInView:touch.view];
    if(location.x > 400) {

        CGPoint yLocation = CGPointMake(playerPaddle.center.x, location.y);
        playerPaddle.center = yLocation;
    }

    if (gameStyle == kGameStyleTwoP) {
        if(location.x < 100) {

            CGPoint yLocation2 = CGPointMake(computerPaddle.center.x, location.y);
            computerPaddle.center = yLocation2;
        }
    }
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何制作启用ActiveViewController的应用程序? - How to make ActiveViewController-enabled app? 如何检测在 iOS 8 上的包含应用程序中启用了应用程序扩展? - How to detect an app extension is enabled in containing app on iOS 8? 在应用中启用了触摸ID和面部ID - Enabled touch id and face id in the app 启用缩放功能后,iPhone iOS如何使UIScrollView与UIRotationGestureRecognizer一起使用? - iPhone iOS how to make UIScrollView work with UIRotationGestureRecognizer when zooming is enabled? 如何检测我的iOS应用程序已启用PIE / ASLR? - How to detect that PIE/ASLR has been enabled for my iOS app? 如何在iOS 4.2之前检查是否为特定应用启用了位置服务? - How to check if location services are enabled for a particular app prior to iOS 4.2? 如何为启用了后台功能的iOS应用程序获取applicationWillTerminate通知? - How to get applicationWillTerminate Notification for an iOS App that has Backgrounding Enabled? iOS如何使UICollectionView下面的UIButton接收触摸? - iOS How to make UIButton below UICollectionView receive touch? iPhone iOS自定义UIButton与CAGradientLayer,如何让它表明触摸? - iPhone iOS custom UIButton with CAGradientLayer, how to make it indicate touch? 在vuforia iOS应用中触摸事件 - Touch event in vuforia iOS app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM