Resizing a rectangle drawn in drawRect

牧云@^-^@ 提交于 2019-12-09 03:56:28

问题


I have two UIViews. My aim is to draw the smallest rectangle which contains both these UIViews. I thought to draw a rectangle using the frame which I'll get out of

CGRectUnion(view1.frame, view2.frame);

But when I move any of the two UIViews, I need to update the frame of the outlining rectangle.

I thought I could do this by :

1) Resizing the previously drawn rectangle.

(or)

2) Deleting the previously drawn rectangle and drawing a new one.

The problem is that, I don't know how to get the instance of the previously drawn rectangle. So, I don't know how to update or delete it..

Can any of you guys help? Is there any other solution to this problem?


回答1:


Perhaps you can declare the following in your .h file:

CGRect *transformingRect;

Doing so should retain the rectangle and its properties so long as whatever view controller this is in is visible and loaded. This way you can have a method that resizes the same drawn rect. You would simply call this whenever you need to resize it.

-(void)resizeRect {
     transformingRect = CGRectUnion(view1.frame, view2.frame);
}


来源:https://stackoverflow.com/questions/17324306/resizing-a-rectangle-drawn-in-drawrect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!