0

I have three UIViews (A, B, C) where A contains B and C. I want to be able to scale view B, by detecting a Pinch gesture with a UIPinchGestureRecognizer and then using CGAffineTransformScale to scale view B.

However, when I scale B it scales OK, but expands outside its original area of the screen - I'd like to keep the area of the screen which contains B the same and just show a smaller piece of it, but magnified.

Is there something I can set to keep the view's area the same?

1 Answers1

0

You can use

viewA.clipsToBounds = YES;

With clipsToBounds set to YES, you will see the part of the viewB and viewC that fits within the bounds of the viewA. Otherwise, if clipsToBounds is set to NO, you will see the entire viewB and viewC, even the parts are outside the viewA

Faisal Ali
  • 1,135
  • 10
  • 17
  • To "initWithFrame:(CGRect)frame" for view A, I added: [self setClipsToBounds:YES]; However, when I expand view B, it covers the area of view C. When I'm creating view B, I set the bounds as follows: [self setBounds:CGRectMake(ROOTX, ROOTY, GRIDX, GRIDY )]; (which maps to 0,0,400,400) – Flaming Moe Apr 06 '14 at 07:16
  • Sorry - editing problems in my previous answer: To "initWithFrame:(CGRect)frame" for view A, I added: [self setClipsToBounds:YES]; However, when I expand view B, it covers the area of view C. When I'm creating view B, I set the bounds as follows: [self setBounds:CGRectMake(ROOTX, ROOTY, GRIDX, GRIDY )]; (which maps to 0,0,400,400) – Flaming Moe Apr 06 '14 at 07:22
  • so you want viewB and viewC not to collide with each other ? – Faisal Ali Apr 06 '14 at 07:25
  • Yes - if I can stop this. – Flaming Moe Apr 06 '14 at 07:33
  • then you have to add condition when you are handling gesturerecognizer – Faisal Ali Apr 06 '14 at 07:34
  • At the start, the two views are next to another, so any scaling will move into the other view. Going back a step, I'm trying to "magnify" the data in view, so instead of showing a 400 square units of data in a 400 unit square, I want to show 200 square units twice as big in the 400 unit square area. Am I using the wrong approach? At the moment the I have: -(void)zoom:(UIPinchGestureRecognizer *)recognizer { recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale); recognizer.scale = 1; } – Flaming Moe Apr 06 '14 at 07:48
  • You can try http://stackoverflow.com/a/5154514/2553526 to limit your transformation.. – Faisal Ali Apr 06 '14 at 08:19