gpt4 book ai didi

iphone - UITextField 停止摇动事件?

转载 作者:行者123 更新时间:2023-11-28 23:19:08 26 4
gpt4 key购买 nike

对于那些使用图形化工作的人,这里是 View 层次结构图:

Root View -> UINavigationController -> UITableView -> 编辑 View -> 问题 UITextfield

基本上,当设备摇动时,- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; 在我的 Root View 中被调用。

当用户点击“编辑”图标(一支笔,在屏幕底部 - 不是传统的 UINavigationBar 编辑按钮)时,主视图会为其自身添加一个 subview 并使用自定义动画将其显示在屏幕上动画片。

此 subview 包含一个 UINavigationController,其中包含一个 UITableView。 UITableView,当一个单元格被点击时,加载一个 subview 到它自己。第二个 subview 是罪魁祸首。出于某种原因,第二个 subview 中的 UITextField 导致了问题。

当用户点击 View 时,主视图不会响应摇动,除非 UITextField 处于事件状态(处于编辑模式?)。

附加信息:

我的运动事件处理程序:

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"%@", [event description]);
SystemSoundID SoundID;
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"shake" ofType:@"aif"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &SoundID);
AudioServicesPlayAlertSound(SoundID);
[self genRandom:TRUE];
}

genRandom: 方法:

/* Generate random label and apply it */
-(void)genRandom:(BOOL)deviceWasShaken{
if(deviceWasShaken == TRUE){
decisionText.text = [NSString stringWithFormat: (@"%@", [shakeReplies objectAtIndex:(arc4random() % [shakeReplies count])])];
}else{
SystemSoundID SoundID;
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"string" ofType:@"aif"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &SoundID);
AudioServicesPlayAlertSound(SoundID);
decisionText.text = [NSString stringWithFormat: (@"%@", [pokeReplies objectAtIndex:(arc4random() % [pokeReplies count])])];
}
}

shakeRepliespokeReplies 都是字符串的 NSArrays。一种用于当屏幕的某个部分被戳时,一种用于当设备被摇动时。该应用将从 NSArray 中随机选择一个字符串并显示在屏幕上。

与往常一样,代码示例非常受欢迎。 我添加了自己的内容来帮助解释问题。

最佳答案

尝试使用[self.view endEditing:YES];

对于玻璃般的键盘使用:

[textfield setKeyboardAppearance:UIKeyboardAppearanceAlert];

希望这对您有所帮助。谢谢,马杜普

关于iphone - UITextField 停止摇动事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2901616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com