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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:54:44+00:00 2026-05-27T23:54:44+00:00

I have a large UIScrollView which contains a CATiledLayer which I’m using to draw

  • 0

I have a large UIScrollView which contains a CATiledLayer which I’m using to draw tiles of a much larger in drawRect: like this:

- (void)drawRect:(CGRect)rect {
    int firstCol = floorf(CGRectGetMinX(rect) / tileSize);
    int lastCol = floorf((CGRectGetMaxX(rect)-1) / tileSize);
    int firstRow = floorf(CGRectGetMinY(rect) / tileSize);
    int lastRow = floorf((CGRectGetMaxY(rect)-1) / tileSize);

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    CGContextTranslateCTM(context, 0, tileSize);
CGContextScaleCTM(context, 1.0, -1.0);

    for( int row = firstRow; row <= lastRow; row++ ) {
    for( int col = firstCol; col <= lastCol; col++ ) {
            UIImage = [self getTileWithRow:row column:col];

            CGRect tileRect = CGRectMake((col * tileSize), 
                                         row * tileSize),
                                         tileSize, tileSize);

            CGContextTranslateCTM(context, 0, tileRect.size.height);
            CGContextScaleCTM(context, 1.0, -1.0);
            CGContextDrawImage(context, tileRect, tile.CGImage);
        }
    }

    CGContextRestoreGState(context);
}

This works when I comment out the CGContextSaveGState, CGContextSaveGState, CGContextScaleCTM and CGContextRestoreGState calls but the images are upside down. With the calls in place the image is not drawn at all. I could use [tile drawInRect:] but that draws the rows in reverse which screws up the larger image.

What am I doing wrong with the translation?

EDIT: Moved save/restore and transform out of the loop as suggested but it’s still not drawing anything.

  • 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-27T23:54:44+00:00Added an answer on May 27, 2026 at 11:54 pm

    Setting the right transformations to flip the content vertically is notoriously hard. The likely cause of not seeing anything, is because the transformations move the image outside of the rect. I have made it work before, but don’t remember how I did it. Now I set “geometryFlipped = YES” on the CATiledLayer instead, which does the flipping for me.

    By the way, why don’t you set the “tileSize” of the CATiledLayer to the size of your tiles, then you don’t need this for-loop tile mapping stuff. The drawRect is called once for each of your tiles, so you can then do simply:

    - (void)drawRect:(CGRect)rect 
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
    
        int col = floorf(CGRectGetMinX(rect) / tileSize);
        int row = floorf(CGRectGetMinY(rect) / tileSize);
    
        UIImage tile = [self getTileWithRow:row column:col];
    
        CGContextDrawImage(context, rect, tile.CGImage);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large UIScrollView with content, which is getting updated when user scrolls
I have a Graph being drawn inside a UIScrollView . It's one large UIView
I have large images displayed in a grouped tableview. I would like the images
I have placed the uiscrollview for viewcontroller. Then I have set my large size
I have a simple ViewController that looks like this: @interface MyViewController : UIViewController<UIScrollViewDelegate> {
I have implemented a large list of views in a UIScrollView. I cannot use
I have a Paging UIScrollView with a contentSize large enough to hold a number
I am developing an application which doesn't have large requirements for data storage. I
So i have a gui, designed using QT, c++. I have large amount of
I use UIScrollView to make large-sized (larger than 320px) UI on iPhone. I made

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.