【问题标题】:Touch Began method issue?触摸开始方法问题?
【发布时间】:2011-03-14 06:01:49
【问题描述】:

我创建了一个应用程序,我想在其中使用 touchbegan 方法。为此,我使用了以下代码:


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //Get all the touches.
    NSSet *allTouches = [event allTouches];

    //Number of touches on the screen
    if([allTouches count] > 0 && self.view!=comparedView.view) 
    {
        //Navigate to next screen here likewise you generally do

        ActionViewController *actController = [[ActionViewController alloc] init];
        UINavigationController *nvController = [[UINavigationController alloc]
                                                initWithRootViewController:actController];
        nvController.navigationBarHidden = YES;
        CGRect frame = [[nvController navigationBar] frame];
         frame = CGRectMake(0.0,0.0, 320.0, 460.0);
        [[nvController navigationBar] setFrame:frame];
        [self setView:[nvController view]];
        [actController release];

    }

}

在我的第一个视图中触摸屏幕上的任意位置时,将执行以下代码并转到下一个视图。但问题是,当我转到最后一个视图并触摸该视图中的 imageview 时,会调用上述方法。

我不知道它是如何发生的。

【问题讨论】:

    标签: iphone objective-c cocoa-touch


    【解决方案1】:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 每次都会被调用,直到视图控制器被释放或触摸事件被禁用。

    每次都会创建视图并将其添加到同一个视图控制器,因此所有视图都会调用触摸开始

    【讨论】:

    • 不,但它没有在第二个视图中被调用,它在第三个视图中被调用,仅在特定区域而不是整个屏幕。
    • self.view!=comparedView.view 打印 NSLog 一样,你会找到原因
    猜你喜欢
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多