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 8107341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:44:20+00:00 2026-06-06T00:44:20+00:00

I have a very large UIView approx 3000×3000 in size. In this large view

  • 0

I have a very large UIView approx 3000×3000 in size. In this large view I do some free form drawing with stylus or finger on an iPad. Here is my code for my touches began and moved methods.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{    

        Line_Point * to_be_added = [[Line_Point alloc] init];
        to_be_added.line_color = [UIColor colorWithCGColor: current_color.CGColor];
        to_be_added.line_pattern = [NSString stringWithString: current_line_pattern]; 

        UITouch *touch = [[event touchesForView:self] anyObject];

        CGPoint location = [touch locationInView:self];
        to_be_added.point = [NSValue valueWithCGPoint:(location)];  

        if (self.points == nil)
        {
            NSMutableArray *newPoints = [[NSMutableArray alloc] init];
            self.points = newPoints;
            [newPoints release];
        }

        [self.points addObject:to_be_added];           



}

Here is my touches moved method which seems to be causing the issue because it isnt getting called enough because the app calls setNeedsDisplay

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

        Line_Point * to_be_added = [[Line_Point alloc] init];
        to_be_added.line_color = [UIColor colorWithCGColor: current_color.CGColor];
        to_be_added.line_pattern = [NSString stringWithString: current_line_pattern];

        UITouch * touch = [[event touchesForView:self] anyObject];
        CGPoint location = [touch locationInView:self];
        to_be_added.point = [NSValue valueWithCGPoint:(location)];

        [self.points addObject:to_be_added];           


        [self setNeedsLayout]; 

}

Now here is my drawRect method which displays the drawing

-(void)drawRect:(CGRect)rect
{
 if (self.points.count == 0)        
    {

    }
    else 
    {    
        Line_Point * first = [self.points objectAtIndex:0];
        CGContextRef context2 = UIGraphicsGetCurrentContext();
        CGContextSetStrokeColorWithColor(context2, first.line_color.CGColor);
        if ([first.line_pattern isEqualToString:@"normal"]) 
        {
            CGContextSetLineWidth(context2, 4.0);
            CGContextSetLineDash(context2, 0, NULL, 0);
        }
        else if([first.line_pattern isEqualToString:@"thick"])            
        {
            CGContextSetLineWidth(context2, 6.0);
            CGContextSetLineDash(context2, 0, NULL, 0);
        }
        else if([first.line_pattern isEqualToString:@"dotted"])            
        {
            CGFloat Pattern[] = {5, 5, 5, 5};
            CGContextSetLineDash(context2, 0, Pattern, 4);
        }
        else if([first.line_pattern isEqualToString:@"super_dotted"])            
        {
            CGFloat Pattern[] = {1, 2, 1, 2}; 
            CGContextSetLineDash(context2, 0, Pattern, 4); 
        }           
        CGPoint firstPoint2 = [first.point CGPointValue];
        CGContextBeginPath(context2);
        CGContextMoveToPoint(context2, firstPoint2.x, firstPoint2.y);

        int i2 = 1;
        while (i2 < self.points.count)
        {
            Line_Point * nextPoint = [self.points objectAtIndex:i2]; 

            if (nextPoint.point.CGPointValue.x < 0 && nextPoint.point.CGPointValue.y < 0)
            {
                CGContextDrawPath(context2, kCGPathStroke);

                if (i2 < (self.points.count-1))
                {

                    CGContextBeginPath(context2);
                    Line_Point * nextPoint2 = [self.points objectAtIndex:i2+1];                
                    CGContextMoveToPoint(context2, nextPoint2.point.CGPointValue.x, nextPoint2.point.CGPointValue.y);
                    CGContextSetStrokeColorWithColor(context2, nextPoint2.line_color.CGColor);
                    if ([nextPoint2.line_pattern isEqualToString:@"normal"]) 
                    {
                        CGContextSetLineWidth(context2, 4.0);
                        CGContextSetLineDash(context2, 0, NULL, 0);
                    }
                    else if([nextPoint2.line_pattern isEqualToString:@"thick"])            
                    {
                        CGContextSetLineWidth(context2, 6.0);
                        CGContextSetLineDash(context2, 0, NULL, 0);
                    }
                    else if([nextPoint2.line_pattern isEqualToString:@"dotted"])            
                    {
                        CGFloat Pattern[] = {5, 5, 5, 5};
                        CGContextSetLineDash(context2, 0, Pattern, 4);  
                    }
                    else if([nextPoint2.line_pattern isEqualToString:@"super_dotted"])            
                    {
                        CGFloat Pattern[] = {1, 2, 1, 2}; 
                        CGContextSetLineDash(context2, 0, Pattern, 4);
                    }        
                    i2 = i2 + 2;

                }
                else
                    i2++;
            }
            else
            {
                CGContextAddLineToPoint(context2, nextPoint.point.CGPointValue.x, nextPoint.point.CGPointValue.y);
                i2++;
            }
        }

        CGContextDrawPath(context2, kCGPathStroke);
    }

The app lags incredibly when drawing in the free form mode. I believe it is because the view is too large and setNeedsDisplay is reloading the entire view every time the touches moved method is called. Is there a way to speed up the setNeedsDisplay method so the free form drawing does not lag on the iPad. Can i just target the context where the drawing is occurring not reload the whole thing? When I adjust the size to about 1000×1000 it does not have the lag problem.

Thanks for any help on the matter.

EDIT TRYED USING
-SetNeedsDisplayinRect

The UIView is wrapped inside a UISCrollview and here is the code.

   -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
   {

    Line_Point * to_be_added = [[Line_Point alloc] init];
    to_be_added.line_color = [UIColor colorWithCGColor: current_color.CGColor];
    to_be_added.line_pattern = [NSString stringWithString: current_line_pattern];

    UITouch * touch = [[event touchesForView:self] anyObject];
    CGPoint location = [touch locationInView:self];
    to_be_added.point = [NSValue valueWithCGPoint:(location)];

    [self.points addObject:to_be_added];           


          CGRect visibleRect;
        visibleRect.origin = big_view.scrollable_view.contentOffset;
        visibleRect.size = CGSizeMake(950, 500);            
        [self setNeedsDisplayInRect:visibleRect];  

 }

This method of approach does not help either.

Thanks again if you can help.

  • 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-06T00:44:22+00:00Added an answer on June 6, 2026 at 12:44 am

    you can use

    - (void)setNeedsDisplayInRect:(CGRect)invalidRect
    

    instead of -setNeedsDisplay

    another solution (if there is too many points and the app lags because of drawing them) – not to render all points every time when -drawInRect is called. You can, for example, at every 10-th call of it save image from current context and then display only image.

    Update:

    try adding

    +(Class)layerClass
    {
    return [CATiledLayer class];
    }
    

    to your view in scrollView

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very large website which uses a lot of cookies. There are approx.
I have very large files (more than 10Gb). I need only some lines from
I have large list of the drop-down menu. Some of the option have very
Suppose, I have very large foreach loop. I want put this loop into try
I have a very large file as: filename.bz2 , how can I view the
We have some very large data files (5 gig to 1TB) where we need
I have a very large file that looks like this (see below). I have
I have very large database and I'm use an advanced search form similar to
I have a very large js file, approximately 1200 lines, and some of the
I have a very large table called paypal_ipn_orders . In this table I have

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.