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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:15:03+00:00 2026-06-15T16:15:03+00:00

My UIView structure: I have a master UIView (actually UIScrollView , but it’s only

  • 0

My UIView structure:
I have a "master" UIView (actually UIScrollView, but it’s only purpose scrolling per pagination).
As a subView on this "master" I have my "pageView" (subclass of UIScrollView). This UIScrollView can have any content (e.g. a UIImageView).
The "master" has another subView: PaintView (subclass of UIView). With this view, I track the finger movements and draw it.

The structure looks like this:

[master.view addSubview: pageView];
[master.view addSubview: paintView];

I know when the user zooms in (pageView is responsible for this) and over delegate/method calls I change the frame of paintView according to the zoom change, during the zoom action.
After zooming (scrollViewDidEndZooming:withView:atScale) I call a custom redraw method of paintView.

Redraw method and drawRect:

-(void)redrawForScale:(float)scale {
    for (UIBezierPath *path in _pathArray) {
        //TransformMakeScale...
    }
    [self setNeedsDisplay];
} 

-(void)drawRect:(CGRect)rect {
    for (UIBezierPath *path in _pathArray) {
        [path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
    } 
}

The problem:
When I zoom-in, I receive a memory warning and the app crashes.

In the Allocations profiler I can see that the app own a lot of memory, but I can’t see why.
When I don’t call 'setNeedDisplay' after my 'redrawForScale' method the app isn’t crashing.

When I log the rect in drawRect I see values like this: {{0, 0.299316}, {4688, 6630}}.

  • 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-15T16:15:05+00:00Added an answer on June 15, 2026 at 4:15 pm

    The problem is (re)drawing such a huge CGRect (correct me if this is wrong).
    The solution for me is to avoid calling a custom drawRect method. In some stackoverflow answers (and I think somewhere in the Appls docs) it was mentioned that a custom drawRect: will reduce the performance (because iOS can’t do some magic on a custom drawRect method).

    My solution:
    Using a CAShapeLayer. For every UIBezierPath I create a CAShapeLayer instance, add the UIBezierPath to the path attribute of the layer and add the layer as a sublayer to my view.

    CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] initWithLayer:self.layer];
    shapeLayer.lineWidth = 10.0;
    shapeLayer.strokeColor = [UIColor blackColor].CGColor;
    shapeLayer.fillColor = [UIColor clearColor].CGColor;
    shapeLayer.path = myBezierPath.CGPath;
    [self.layer addSublayer:shapeLayer];
    

    With this solution I don’t need to implement drawRect. So the App won’t crash, even with a big maximumZoomScale.

    After changing the UIBezierPath (translate, scale, change color) I need to set the changed bezierPath to the shapeLayer again (set the path attribute of shapeLayer again).

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

Sidebar

Related Questions

I have a structure like this.... UITableViewController -> UITableViewCell -> UIView I need the
I have the following structure of the views UIView(1) |--> UIScrollView |-----------> UIView(2) |------>
I have a UIView, it is not inside UIScrollView. I would like to move
I have the following structure: UIViewController > UIView (self.view) > UITableView (self.tableView - IBOutlet)
I have custom UIView class GestureView. I have a forward declaration for this class
I have a UIView which contains lot of labels, buttons, textviews. But there is
This is how the structure looks like. --- UIView ---- ScrollView --- TableView .
for(UIView *subview in [scrollView subviews]) { NSLog(@subviews Count=%d,[[scrollView subviews]count]); //[subview release]; [subview removeFromSuperview]; }
I got this warning: 'UIView' may not respond to 'addSubview:withAnimation:' The line of code
I'm building an iPhone app, with the following structure: I have the MainViewController which

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.