Search code examples
objective-ciphonexcodeuiviewuiscrollview

How to open a new view when touching on a uiview?


I have a UIScrollView with UIView added as subview. 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

here is an image of my view

alt text


Solution

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