【发布时间】:2010-11-23 11:34:05
【问题描述】:
当我尝试使用 (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event 来捕获抖动事件时,我遇到了一些问题。问题是该函数甚至没有运行,即使我覆盖 canBecomeFirstResponder 并将其设置为返回 YES。看过其他人的帖子有这个问题,但没有找到答案。
感谢您的帮助!
第一个示例 .h(从 UIView 继承的类 - 从应用委托类“调用”) {
@class TestApplicationView;
@interface TestApplicationView : UIView {
IBOutlet UIView *view;
}
}
第一个例子.m {
- (id)initWithCoder:(NSCoder *)coder
{
[self setUpView];
return self;
}
- (id)initWithFrame:(CGRect)frame
{
[self setUpView];
return self;
}
- (void)setUpView
{
[self becomeFirstResponder];
NSLog(@"First Responder - %d", [self isFirstResponder]);
}
}
第二个例子.h(继承自 UIApplicationDelegate 和 UIScrollViewDelegate 的类) {
#import <UIKit/UIKit.h>
@class TestApplicationViewController;
@interface TestApplicationAppDelegate : NSObject <UIApplicationDelegate, UIScrollViewDelegate> {
IBOutlet UIWindow *window;
IBOutlet UIScrollView *scrollView;
}
}
第二个例子.m {
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[self becomeFirstResponder];
}
}
-- 第二个例子返回如下警告:'TestApplicationAppDelegate'可能不响应'-becomeFirstResponder'
【问题讨论】:
标签: iphone cocoa cocoa-touch motion