小编And*_*wDK的帖子

touchesBegan&touchesMoved

所以这是一个奇怪的问题.我有一个响应touchesMoved:&的UIImageView touchesBegan:,它完美地运行.我遇到的主要问题是如果你把手指放在说image1然后然后用手指按住图像1你会用另一根手指按下image2.

反过来,这将再次触发image1.不希望这种情况发生.我希望能够在同时推动两个图像时使用Multi Touch,而不是一遍又一遍地触发它们.必须有一些东西我必须添加,以阻止这种情况发生.

码:

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches]; 
    for (UITouch *touch in allTouches) 
    { 
        CGPoint location = [touch locationInView:touch.view];
        if(CGRectContainsPoint(image1.frame, location) && lastButton != image1) {
            //Play Sound
            NSString *path = [[NSBundle mainBundle] pathForResource:@"sound1" 
                                                             ofType:@"wav"];
            SystemSoundID soundID;
            AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path]
                                             , &soundID);
            AudioServicesPlaySystemSound (soundID); 
            //
            lastButton = image1;
        }
        if(CGRectContainsPoint(image2.frame, location) && lastButton != image2) {
            //Play Sound
            NSString *path = [[NSBundle mainBundle] pathForResource:@"sound2" 
                                                             ofType:@"wav"];
            SystemSoundID soundID;
            AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path]
                                             , &soundID); …
Run Code Online (Sandbox Code Playgroud)

iphone xcode cocoa-touch objective-c

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

多点触控开始

我试图让touchesBegan回应多点触控时遇到一些问题.

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

NSSet *allTouches = [event allTouches]; 
for (UITouch *touch in allTouches) 
{ 
CGPoint location = [touch locationInView:touch.view];
if(CGRectContainsPoint(snare.frame, location) && lastButton != snare) {
    //Swap Image
    snareImg.image = snareImgDown;
    [self performSelector:@selector(swapBack) withObject:nil afterDelay:0.1];
    //Play Sound
    NSString *path = [[NSBundle mainBundle] pathForResource:@"snare" 
                                                     ofType:@"wav"];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path]
                                     , &soundID);
    AudioServicesPlaySystemSound (soundID); 
    //
    lastButton = snare;
}
else if(CGRectContainsPoint(hiHat.frame, location) && lastButton != hiHat) {
    //Play Sound
    NSString *path = [[NSBundle mainBundle] pathForResource:@"hi_hat" 
                                                     ofType:@"wav"];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c touch

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

标签 统计

objective-c ×2

xcode ×2

cocoa-touch ×1

iphone ×1

touch ×1