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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:04:07+00:00 2026-05-28T04:04:07+00:00

To describe my project: I have a rectangle UIImageView frame floating over a white

  • 0

To describe my project:

I have a rectangle UIImageView frame floating over a white layer. Inside the UIImageView, I’m successfully creating the illusion that it is showing a portion of a background image behind the white layer. You can drag the rectangle around, and it will “redraw” the image so that you can peer into what is behind the white. Its basically this code:

//whenever the frame is moved, updated the CGRect frameRect and run this:

self.newCroppedImage = CGImageCreateWithImageInRect([bgImage.image CGImage], frameRect);
 frame.image = [UIImage imageWithCGImage:self.newCroppedImage];

Anyhow, I also have a rotation gesture recognizer that allows the user to rotate the frame (and consequentially rotates the image). This is because the CGRect sent to the CGImageCreateWithImageInRect is still oriented at its original rotation. This breaks the illusion that you’re looking through a window because the image you see is rotated when only the frame should appear that way.

So ideally, I need to take the rotation of my frame and apply it to the image created from my bgImage. Does anyone have any clues or ideas on how I could apply this?

  • 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-28T04:04:07+00:00Added an answer on May 28, 2026 at 4:04 am

    I suggest you take a different approach. Don’t constantly create new images to put in your UIImageView. Instead, set up your view hierarchy like this:

    White view
        "Hole" view (just a regular UIView)
            Image view
    

    That is, the white view has the hole view as a subview. The hole view has the UIImageView as its subview.

    The hole view must have its clipsToBounds property set to YES (you can set it with code or in your nib).

    The image view should have its size set to the size of its image. This will of course be larger than the size of the hole view.

    And this is very very important: the image view’s center must be set to the hole view’s center.

    Here’s the code I used in my test project to set things up. The white view is self.view. I start with the hole centered in the white view, and I set the image view’s center to the hole view’s center.

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:YES];
    
        CGRect bounds = self.view.bounds;
        self.holeView.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
        self.holeView.clipsToBounds = YES;
    
        bounds = self.holeView.bounds;
        self.imageView.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
        self.imageView.bounds = (CGRect){ CGPointZero, self.imageView.image.size };
    
    }
    

    I also set the image view’s size to the size of its image. You might want to set it to the size of the white view.

    To pan and rotate the hole, I’m going to set holeView.transform. I’m not going to change holeView.frame or holeView.center. I have two instance variables, _holeOffset and _holeRotation, that I use to compute the transform. The trick to making it seem like a hole through the white view, revealing the image view, is to apply the inverse transform to the image view, undoing the effects of the hole view’s transform:

    - (void)updateTransforms {
        CGAffineTransform holeTransform = CGAffineTransformIdentity;
        holeTransform = CGAffineTransformTranslate(holeTransform, _holeOffset.x, _holeOffset.y);
        holeTransform = CGAffineTransformRotate(holeTransform, _holeRotation);
        self.holeView.transform = holeTransform;
        self.imageView.transform = CGAffineTransformInvert(holeTransform);
    }
    

    This trick of using the inverse transform on the subview only works if the center of the subview is at the center of its superview. (Technically the anchor points have to line up, but by default the anchor point of a view is its center.)

    I put a UIPanGestureRecognizer on holeView. I configured it to send panGesture: to my view controller:

    - (IBAction)panGesture:(UIPanGestureRecognizer *)sender {
        CGPoint offset = [sender translationInView:self.view];
        [sender setTranslation:CGPointZero inView:self.view];
        _holeOffset.x += offset.x;
        _holeOffset.y += offset.y;
        [self updateTransforms];
    }
    

    I also put a UIRotationGestureRecognizer on holeView. I configured it to send rotationGesture: to my view controller:

    - (IBAction)rotationGesture:(UIRotationGestureRecognizer *)sender {
        _holeRotation += sender.rotation;
        sender.rotation = 0;
        [self updateTransforms];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone I have a question that I will describe as good as I
I'm starting a new project from scratch and have written User Stores to describe
I currently have a wcf service library project that includes my service contract &
I have an old post Re-Installing IPhone App From Inside The App That old
I have a C++ project that will compile just fine in 2008 and in
I have a project that I want the user to input the path (folder
I have easily created a JSF project with NetBeans that delivers a web service
I have been reading many posts that describe my problem but I cannot find
We have a project that is starting to get large, and we need to
We have an existing PHP page (from an earlier project) which could be described

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.