简体   繁体   English

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

[英]How to open a new view when touching on a uiview?

I have a UIScrollView with UIView added as subview. 我有一个UIScrollView其中UIView添加为子视图。 Now how do I open a new view when i touch on the view ? 现在,当我触摸视图时如何打开一个新视图?

I want new view to appear .before this i have buttons on my view...so button have the method "addtarget perform selector"...from that i am loading a new view 我希望出现新视图。在此之前,我在视图上有按钮...因此按钮具有方法“ addtarget perform selector” ...从此我正在加载新视图

here is an image of my view 这是我的观点

替代文字

For example try following code (add it to your view): 例如,尝试以下代码(将其添加到视图中):

- (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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM