uiview width is zero
I added a uigesture to my uiview using the following code
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
[pinchRecognizer setDelegate:self];
[holderView addGestureRecognizer:pinchRecognizer];
[pinchRecognizer release];
and the code of scalling is
if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
lastScale = 1.0;
return;
}
CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]);
CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
[[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform];
lastScale = [(UIPinchGestureRecognizer*)sender scale];
OldTransform = newTransform;
OldCenter = [(UIPinchGestureRecognizer*)sender view].center;
the problem before the zooming I can get the width and height of holdview but after scaling it return zero
I use the following code to display
NSLog(@" the rectangle %f , %f ,%f, %f ", holderView.frame.origin.x, holderView.frame.origin.y, holderView.bounds.size.width , holderView.bounds.size.height ) ;
another problem is that when I add subview above it all the values return from the holderview t开发者_如何学JAVAhe size the origin ,.. become zero any suggestion to solve that
Setting the transform of a view does not change the values of its frame property. So even if the frame reports back that the width is 100, it might visually be 50, or whatever, due to the transform.
The reason you get 0 for the width of your frame is probably because you either set it to 0 at some point, or haven't set it yet. You need to provide a default size to make your view visible.
精彩评论