Ios 在选项卡式应用程序中更改选项卡后,运动功能不起作用
我是新来的 我正在开发一个选项卡式应用程序 我想有一个标签与震动功能,合并Ios 在选项卡式应用程序中更改选项卡后,运动功能不起作用,ios,motion-detection,Ios,Motion Detection,我是新来的 我正在开发一个选项卡式应用程序 我想有一个标签与震动功能,合并 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.subtype == UIEventSubtypeMotionShake) { NSLog(@"shook"); } } 这工作得非常好,直到我从这个FirstViewController切换到另一个,然后再回来。
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.subtype == UIEventSubtypeMotionShake)
{
NSLog(@"shook");
}
}
这工作得非常好,直到我从这个FirstViewController切换到另一个,然后再回来。一旦我回到FirstViewController,抖动功能似乎根本不起作用。有什么想法吗
我的其他组件如下所示
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (void)viewDidAppear:(BOOL)animated
{
[self canBecomeFirstResponder];
[super viewDidAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated
{
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
似乎每次在选项卡之间切换时都不会调用ViewDidDisplay: 正如这里的答案所建议的,实现UITabBarController委托didSelectViewController,并调用视图控制器的VIEWDIDISPENCE方法 或者仍然实现委托,只检测所选的视图控制器,如果它是FirstViewController,则调用方法canBecomeFirstResponder 例如,如果已将FirstViewController声明为选项卡栏的属性:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
if ([viewController isKindOfClass:[FirstViewController class]]) {
[viewController canBecomeFirstResponder];
}
}