调整drawRect中绘制的矩形的大小 [英] Resizing a rectangle drawn in drawRect

查看:148
本文介绍了调整drawRect中绘制的矩形的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 UIViews 。我的目标是绘制包含这些 UIView 的最小矩形。我想用框架绘制一个矩形,我将从中获取

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);

但当我移动两个 UIView 中的任何一个时,我需要更新框架大纲矩形。

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

我以为我可以这样做:

1)调整以前绘制的矩形的大小。

1) Resizing the previously drawn rectangle.

(或)

2)删除先前绘制的矩形并绘制一个新矩形。

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?

推荐答案

也许您可以在.h文件中声明以下内容:

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

CGRect *transformingRect;

这样做应该保留矩形及其属性,只要它所在的任何视图控制器都是可见的,加载。这样你就可以有一个方法来调整同一个绘制的rect的大小。只要你需要调整它就可以调用它。

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);
}

这篇关于调整drawRect中绘制的矩形的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆