ios - How to get frame of subview after apply transform on mainView? -


i have created mainview objcet of uiview , added 1 subview on it. applied transform on mainview reducing frame size. frame of subview of mainview not reduced. how reduce size of subview.

- (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.     cgfloat widthm=1200.0;     cgfloat heightm=1800.0;     uiview *mainview = [[uiview alloc] initwithframe:cgrectmake(0, 0, widthm, heightm)];     mainview.backgroundcolor = [uicolor colorwithpatternimage:[uiimage imagenamed:@"te.png"]];     [self.view addsubview:mainview];     cgfloat yourdesiredwidth = 250.0;     cgfloat yourdesiredheight = yourdesiredwidth *heightm/widthm;     cgaffinetransform scalingtransform;     scalingtransform = cgaffinetransformmakescale(yourdesiredwidth/mainview.frame.size.width, yourdesiredheight/mainview.frame.size.height);      mainview.transform = scalingtransform;     mainview.center = self.view.center;     nslog(@"mainview:%@",mainview);     uiview *submainview= [[uiview alloc] initwithframe:cgrectmake(100, 100, 1000, 1200)];     submainview.backgroundcolor = [uicolor redcolor];     [mainview addsubview:submainview];     nslog(@"submainview:%@",submainview);  } 

nslog of these views:

mainview:<uiview: 0x8878490; frame = (35 62.5; 250 375); transform = [0.208333, 0, 0, 0.208333, 0, 0]; layer = <calayer: 0x8879140>> submainview:<uiview: 0x887b8c0; frame = (100 100; 1000 1200); layer = <calayer: 0x887c160>> 

here width of mainview 250, width of subview 1000. when output in simulator, subview occupied correctly, it's not cross mainview. how possible? how frame of subview respect mainview frame after transformation?

what you're seeing expected behavior. frame of uiview relative parent, doesn't change when apply transformation superview. while view appear 'distorted' too, frame won't reflect changes since it's still @ exact same position relative parent.
however, assume frame of view relative topmost uiview. in case uikit offers these functions:

  • – [uiview convertpoint:toview:]
  • – [uiview convertpoint:fromview:]
  • – [uiview convertrect:toview:]
  • – [uiview convertrect:fromview:]

i applied these example:

cgrect frame = [[self view] convertrect:[submainview frame] fromview:mainview]; nslog(@"submainview:%@", nsstringfromcgrect(frame)); 

and output:

submainview:{{55.8333, 83.3333}, {208.333, 250}} 

Comments