tôi đã thêm đoạn mã sau vào appDelegate.m tôiiOS: Cách phát hiện chuyển động lắc?
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{
// User was shaking the device. Post a notification named "shake".
[[NSNotificationCenter defaultCenter] postNotificationName:@"shake" object:self];
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
- (void)shakeSuccess
{
// do something...
}
và sau đó tôi nói thêm:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// INIT THE BACKGROUND PATH STRING
[self refreshFields];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
***[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shakeSuccess) name:@"shake" object:nil];***
return YES;
}
Khi tôi bắt đầu ứng dụng của tôi trên iPhone của tôi, các phương thức có tên "shakeSuccess" không gọi . Tôi nên làm gì để triển khai chức năng này trong ứng dụng của mình? bất kỳ ý tưởng nào?
Tuyệt vời! Nó hoạt động tuyệt vời! Cảm ơn nhiều. – Samblg
Lol và anh ta chưa bao giờ làm điều đó. –
"Phần còn lại" là điểm. – Itachi