Ios6 将Rect连接到手势识别器进行平移?

Ios6 将Rect连接到手势识别器进行平移?,ios6,gestures,Ios6,Gestures,我有一个底部视图(UIView)和一个顶部视图(UIView)。 bottomView有一个红色背景,在IB中,我将topView设置为clearColor,将不透明设置为OFF。 通过以下代码,我实现了在俯视图上创建矩形/窗口并在俯视图上打孔的目标: - (void)drawRect:(CGRect)rect { // Drawing code CGRect holeRect = CGRectMake(100, 100, 100, 100); self.opaque

我有一个底部视图(UIView)和一个顶部视图(UIView)。 bottomView有一个红色背景,在IB中,我将topView设置为clearColor,将不透明设置为OFF。 通过以下代码,我实现了在俯视图上创建矩形/窗口并在俯视图上打孔的目标:

- (void)drawRect:(CGRect)rect
{
    // Drawing code
    CGRect holeRect = CGRectMake(100, 100, 100, 100);

    self.opaque = NO;
    self.backgroundColor = [UIColor clearColor];

    // Start by filling the area with the blue color
    [[UIColor blueColor] setFill];
    UIRectFill( rect );

    // Assume that there's an ivar somewhere called holeRect of type CGRect
    // We could just fill holeRect, but it's more efficient to only fill the
    // area we're being asked to draw.
    CGRect holeRectIntersection = CGRectIntersection( holeRect, rect );

    [[UIColor clearColor] setFill];
    UIRectFill( holeRectIntersection );
}
现在-我想使矩形/窗口可移动。我已将ViewController设置为UIgestureRecognitizerDelegate,并在实现文件中,在viewDidLoad中包含以下代码,这些代码在另一个项目中对我有效:

//为每个ImageView创建平移手势识别器 UIPanGestureRecognizer*pan1Recognizer=[[UIPanGestureRecognizer alloc]initWithTarget:self 操作:@selector(handlePan1From:)]

挑战是,上面的XXX。在我的另一个项目中,我在IB中有一个子视图,其中定义了一个出口,这样我就可以显式地引用它。然而,在这个项目中,我在上面的drawRect中创建了rect,但不确定如何建立这种连接


感谢您的帮助

我能够将我创建的矩形与受手势控制的UIView对齐,并通过将它们一起移动来解决问题。也许不是最优雅的方法,但它很有效,我已经在这个问题上被难倒了一个多星期了,所以naff-to-that和allons-y

创建一个

@property (nonatomic, strong) UIView *holerectView;
然后将视图设置为矩形框架:

 _rect = CGRectMake(100, 100, 100, 100);

self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
不要麻烦用颜色填充矩形;只需为视图创建背景色

_holerectView = [[UIView  alloc] initWithFrame:_rect];
_holerectView.backgroundColor = [UIColor redColor];

[self addSubview:_holeRectView];
在这里:

[_holeRectView addGestureRecognizer:pan1Recognizer];
[_holeRectView addGestureRecognizer:pan1Recognizer];