Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6085355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:37:47+00:00 2026-05-23T11:37:47+00:00

I add a view as sub view using the following code imageview = [[UIImageView

  • 0

I add a view as sub view using the following code

    imageview = [[UIImageView alloc] initWithFrame:[holderView frame]];
    [imageview setImage:cppobject->OutputImage];
    imageview.contentMode = UIViewContentModeScaleAspectFit;

    [holderView addSubview:imageview];
    holderView.contentMode = UIViewContentModeScaleAspectFit ;

    UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
    [pinchRecognizer setDelegate:self];
    [holderView addGestureRecognizer:pinchRecognizer];
    [pinchRecognizer release];

    UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
    [rotationRecognizer setDelegate:self];
    [holderView addGestureRecognizer:rotationRecognizer];
    [rotationRecognizer release];

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:1];
    [panRecognizer setDelegate:self];
    [holderView addGestureRecognizer:panRecognizer];
    [panRecognizer release];

-(void)scale:(id)sender {
}

-(void)rotate:(id)sender {
}

-(void)move:(id)sender {
}

-(void)tapped:(id)sender {
}

I need to draw line when the user use his two fingers to pan and a uilabel (the green one) like in the following image

I had look on How to draw graphics in iphone gesture?

But I couldn’t apply it on the subview , specially the DrawInRect method

in panRecognizer function (move) I want to draw line using

    UIPanGestureRecognizer *gR = (UIPanGestureRecognizer *) sender ; 
    NSValue *value = [NSValue valueWithCGPoint: [gR locationInView:gR.view]]; 
    [Points addObject:value];
    [holderView setNeedsDisplay];

    NSLog(@"End of measuring") ; 

and I will use the points in Points to draw line above all the subviews in

-(void)drawRect:(CGRect)rect { 
  NSLog(@"Entered Draw In Rect");
  if (Measuring) {
    [[UIColor redColor] setStroke];
    UIBezierPath *pathToDraw = [UIBezierPath bezierPath]; 

    for (int n = 1; n < [Points count] - 1 ; n++) { 
      NSValue * value = [Points objectAtIndex:(NSInteger)n];
      CGPoint  point = [value CGPointValue]; 
      [pathToDraw moveToPoint:point];
      value = [Points objectAtIndex:(NSInteger)n+1];
      point = [value CGPointValue];
      [pathToDraw addLineToPoint:point];
    }
    [pathToDraw stroke];
  }
}

the problem is [holderView setNeedsDisplay]; never call or fire drawRect any suggestion or help regarding that

any suggestion

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:37:47+00:00Added an answer on May 23, 2026 at 11:37 am

    The image view being the subview draws on top of the holder view. The imageview is opaque. This means that when the views are drawn there is no part of the holder view that is actually visible, so it’s drawRect call is optimised out.

    Try ordering the views the other way around, so that the holder view is the subview of the imageview. Then the imageview will draw and the holder view will draw on top of it.

    Also, note that you should use the bounds of the parent view as the frame of the subview.

    UIView* subview = [[UIView alloc] initWithFrame:[parentview bounds]];
    

    Edit (add):

    See http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html%23//apple_ref/doc/uid/TP40009503-CH2-SW1
    , specifically under the section “View Hierarchies and Subview Management”:

    “Visually, the content of a subview obscures all or part of the content of its parent view”

    So, try make the imageview the parent, do your initialisation like so:

    // instance variables:
    UIImageView* imageView;
    MyHolderView* holderView;
    
    imageView = [[UIImageView alloc] initWithFrame:mainRect];
    holderView = [[MyHolderView alloc] initWithFrame:[imageView bounds]];
    holderView.opaque = NO;
    holderView.backgroundColor = [UIColor clearColor];
    [imageView addSubview:holderView];
    
    UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:holderView action:@selector(scale:)];
    [pinchRecognizer setDelegate:self];
    [holderView addGestureRecognizer:pinchRecognizer];
    [pinchRecognizer release];
    
    // etc...
    

    Now, the image view is drawn, and the holder view, its subview is drawn on top of it. Now when you call setNeedsDisplay on the holderview it will receive a drawRect: call.

    For example, track the gesture like so. This could be in your view controller or in your MyHolderView view subclass; the example here would be in the MyHolderView class so that the location1 and location2 instance variables can be shared easily with the drawRect: method.:

    -(void)scale:(id)sender {
      if (sender == pinchRecognizer) { // this allows the responder to work with multiple gestures if required
        // get position of touches, for example:
        NSUInteger num_touches = [pinchRecognizer numberOfTouches];
    
        // save locations to some instance variables, like `CGPoint location1, location2;`
        if (num_touches >= 1) {
          location1 = [pinchRecognizer locationOfTouch:0 inView:holderView];
        }
        if (num_touches >= 2) {
          location2 = [pinchRecognizer locationOfTouch:1 inView:holderView];
        }
    
        // tell the view to redraw.
        [holderView setNeedsDisplay];
      }
    }
    

    and then in the holder view drawRect routine:

    -(void)drawRect:(CGRect)rect {
    
      // use instance variables location1 and location2 to draw the line.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I add a label on to the view UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f,
I want to add a subview with animation. I am using add sub view
I want to add a sub view in current view, this sub view is
I want to know how to add image in list view sub item. I
Does anyone else think that the add view dialog in VS is useless or
I asp.net mvc my model classes won't show up in the Add View dialog,
How do I add a View dynamically in an android widget? I realize that
I am trying to add a view to a custom list. The target is
To allow users and site admins to view/add/edit/delete data in my application I decided
In my App, I need to invoke the native add contact view. Is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.