代码之家  ›  专栏  ›  技术社区  ›  Rahul Vyas

触摸uiview时如何打开新视图?

  •  1
  • Rahul Vyas  · 技术社区  · 16 年前

    我有一个添加了uiview作为子视图的滚动视图..现在我如何在触摸视图时打开一个新视图????? 我希望一个新视图出现…在此之前,我的视图上有按钮…所以按钮有方法“addTarget perform selector”…从中我正在加载一个新视图 这是我的视图

    alt text http://www.freeimagehosting.net/uploads/3669826092.png

    1 回复  |  直到 16 年前
        1
  •  1
  •   Harri Siirak    16 年前

    例如,尝试以下代码(将其添加到视图中):

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
    {
        UITouch *touch = [touches anyObject];
        NSUInteger tapCount = [touch tapCount];
        CGPoint location = [touch locationInView:self.view];
    
        switch (tapCount)
        {
             case 1:
             {
                  UIView *view = [[UIView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
                  view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
                  view.backgroundColor = [UIColor whiteColor];
    
                  [self.view addSubview:view];
                  [view release];
             }
             break;
        }
    }