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

  • Home
  • SEARCH
  • 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 8400917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:40:24+00:00 2026-06-09T21:40:24+00:00

I have some UIView subclasses where I draw UIBezierPaths in drawRect. In the viewController

  • 0

I have some UIView subclasses where I draw UIBezierPaths in drawRect. In the viewController that adds these views, I need to do a hit test to see if a tap happened inside the bezier path. I tried creating a UIBezierPath variable in the view subclass, then testing against that. But of course, the offset was completely wrong – I would get hits in the top corner of the screen, rather than over the shape.

Can anyone suggest the best way to do this? Does this make sense, or should I add some code?

Thanks,
James

  • 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-06-09T21:40:26+00:00Added an answer on June 9, 2026 at 9:40 pm

    This is a custom triangle view I have. Its much simpler than a bezier path but I believe it should work about the same. I also have a category that hittests based on alpha level on a pixel-per-pixel basis that I use for UIImages with alpha layers. (Its in this post Retrieving a pixel alpha value for a UIImage)

    - (void)drawRect:(CGRect)rect
    {    
        CGContextRef context = UIGraphicsGetCurrentContext();
    
        CGContextMoveToPoint(context, 0.0, 0.0);
        CGContextAddLineToPoint(context, rect.size.width, 0.0);
        CGContextAddLineToPoint(context, 0.0, rect.size.height);
        CGContextClosePath(context);
    
        CGContextSetFillColorWithColor(context, triangleColor.CGColor);
        CGContextFillPath(context);
    
        CGContextSaveGState(context);
    
        [self.layer setShouldRasterize:YES];
        [self.layer setRasterizationScale:[UIScreen mainScreen].scale];
    
    }
    
    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    {
        CGMutablePathRef trianglePath = CGPathCreateMutable();
        CGPathMoveToPoint(trianglePath, NULL, 0.0, 0.0);
        CGPathAddLineToPoint(trianglePath, NULL, self.frame.size.width, 0.0);
        CGPathAddLineToPoint(trianglePath, NULL, 0.0, self.frame.size.height);
        CGPathCloseSubpath(trianglePath);
    
    
        if (CGPathContainsPoint(trianglePath, nil, point, YES)) {
            CGPathRelease(trianglePath);
            return self;
        } else {
            CGPathRelease(trianglePath);
            return nil;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some buttons in an UIView. My problem is, that they get cut
I have a NIB with a UIView that contains some UILabels, UIButtons etc. and
I have some UI that I need to redraw based on changes to an
According to Apple's docs, Subclasses need not override -[UIView drawRect:] if the subclass is
I am updating some old code and I have a subclassed UIView (GraphView) that
I have a custom view that subclasses UIView. It has a touchesEnded event, however
I have a UIView subclass that I am doing some custom drawing in. When
I have a subclass of UIView that's instantiated in a XIB file. I need
I have a subclass of UIView that implements code to draw CoreText. In the
I have a class that subclasses UIView called DrawView. This class contains custom drawing

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.