私はbottomView(UIView)とtopView(UIView)を持っています。bottomView の背景は赤で、IB では topView を clearColor に、Opaque を OFF に設定しました。次のコードを使用して、topView に四角形/ウィンドウを作成し、bottomView に穴を開けるという目標を達成します。
- (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 を UIGestureRecognizerDelegate として設定し、実装ファイルに、viewDidLoad に別のプロジェクトで機能する次のコードを含めます。
// ImageView ごとにパン ジェスチャ レコグナイザを作成します UIPanGestureRecognizer *pan1Recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan1From:)];
// set self as delegate for gesture recognition
[pan1Recognizer setDelegate:self];
// setup the selector for the pan gesture
pan1Recognizer.minimumNumberOfTouches = 1;
pan1Recognizer.maximumNumberOfTouches = 1;
[XXX addGestureRecognizer:pan1Recognizer];
// ensure user interaction is ENABLED !!!!
[XXX setUserInteractionEnabled:YES];
課題は、上記の XXX です。私の他のプロジェクトでは、明示的に参照できるようにアウトレットが定義された IB のサブビューがありました。ただし、このプロジェクトでは、上記の drawRect で rect を作成しましたが、その接続方法がわかりません。
どんな助けでも大歓迎です!