Iphone sdk 3.0 iphonesdk新增:touchesbreated未调用

Iphone sdk 3.0 iphonesdk新增:touchesbreated未调用,iphone-sdk-3.0,uiview,uiviewcontroller,Iphone Sdk 3.0,Uiview,Uiviewcontroller,我创建了一个非常基本的iPhone应用程序,其中包含基于文件/新Projet/视图的应用程序。 那里没有NIB文件 这是我的代理 h 这是我控制器中的loadView方法 - (void)loadView { CGRect mainFrame = [[UIScreen mainScreen] applicationFrame]; UIView *contentView = [[UIView alloc] initWithFrame:mainFrame]; contentView.back

我创建了一个非常基本的iPhone应用程序,其中包含基于文件/新Projet/视图的应用程序。 那里没有NIB文件

这是我的代理

h

这是我控制器中的loadView方法

 - (void)loadView {
 CGRect mainFrame = [[UIScreen mainScreen] applicationFrame];
 UIView *contentView = [[UIView alloc] initWithFrame:mainFrame];
 contentView.backgroundColor = [UIColor redColor];
 self.view = contentView;
 [contentView release];
}
现在,为了捕获ToucheSBegind事件,我创建了UIView的一个新子类:

h

m

并将我的loadView中的第二行修改为:

 TouchView *contentView = [[UIView alloc] initWithFrame:mainFrame];

为什么从来没有调用TouchesStart?

找到了解决方案:在viewController上调用TouchesStart,而不是在视图上…

如果将loadView更改为:

TouchView *contentView = [[TouchView alloc] initWithFrame:mainFrame];

在TouchView中捕捉触摸应该没有问题。在代码中,您没有创建TouchView实例,而是创建了UIView实例。

非常接近。显然,UIViewController在UIView之前获取touchesBegind/touchesEnded/etc消息。默认情况下,UIViewController不会将消息传递给UIView(通过调用[super TouchesBegind])。因此,如果UIView有控制器,则需要移动或前进到touchs*函数。它令人困惑,而且从未被正确记录,但这是传统的可可方式。。。它也被称为UIView类..:
@interface TouchView : UIView {
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 NSLog(@"Touch detected");

}
 TouchView *contentView = [[UIView alloc] initWithFrame:mainFrame];
TouchView *contentView = [[TouchView alloc] initWithFrame:mainFrame];