Sunday, October 11, 2009

iPhone dev Stupidity 54: Convert rect of zero size

When the rect's width/height is zero, UIView method: convertRect:toView: will not work - it just returns the rect passed in.

To fix:

- (CGRect) extConvertRect: (CGRect) rect toView: (UIView *) view{


if(rect.size.width == 0 || rect.size.height == 0){


CGPoint lt = [self convertPoint: rect.origin toView: view];


return CGRectMake(lt.x, lt.y, rect.size.width, rect.size.height);


}else{


return [self convertRect:rect toView: view];


}


}


No comments: