Detect shake gesture IOS Swift

后端 未结 8 2171
难免孤独
难免孤独 2020-12-08 02:27

I\'m developing a app with a gesture system, basically if I turn the iPhone to left my app will do a function, if I turn the iPhone to Right, other function, with others ges

8条回答
  •  猫巷女王i
    2020-12-08 02:54

    Speedy99's swift answer is in the Objective C version

    - (void)viewDidLoad {
        [super viewDidLoad];
        [self becomeFirstResponder];
    }
    
    - (BOOL)canBecomeFirstResponder{
        return true;
    }
    
    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
        if(event.subtype == UIEventSubtypeMotionShake){
           NSLog(@"Why are you shaking me?");
        }
    }
    

提交回复
热议问题