2

現在、私はコラージュアプリに取り組んでいます。コラージュ フレームを描画したい後、カメラ ロールまたはカメラから画像を追加する必要があります。次のタイプビューが必要です ここに画像の説明を入力

5 つの UIImageView を追加しました。形を描くために、imageview1のようにUIBezierPathを追加しました

UIBezierPath *path1 = [[UIBezierPath alloc] init];

        [path1 moveToPoint:CGPointMake(0, 0)];
        [path1 addLineToPoint:CGPointMake(150, 0)];
        [path1 addLineToPoint:CGPointMake(0, 150)];
        [path1 addLineToPoint:CGPointMake(0, 0)];

 UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(140, 0, 160, 300)];
imgView1 . tag = 2;
imgView1 . userInteractionEnabled = YES;
imgView1. backgroundColor = [UIColor greenColor];
CGPathRef borderPathRef2 = [path1 CGPath];
CAShapeLayer *borderShapeLayer2 = [[CAShapeLayer alloc] init];
[borderShapeLayer2 setPath:borderPathRef2];
[[imgView1 layer] setMask:borderShapeLayer2];
imgView1.layer.masksToBounds = YES;
[borderShapeLayer2 release];

[view1 addSubview:imgView1];

このように、5つすべてに対して行いました。しかし、imageView5タッチを追加した後、フレームが他の4つのイメージビューと重なるため、他の4つのビューすべてでタッチが検出されません。

したがって、これを設計する方法がわかりません。タッチ操作ですべての画像ビューに画像を追加する必要があります。

私を助けてください。誰かがこれについて何か考えを持っている場合は、共有してください。

前もって感謝します。

以下は、Insta Collage アプリからの例 2 です。 ここに画像の説明を入力

4

3 に答える 3

3

UIViewのhitTest:withEvent:メソッドをオーバーライドすることで、この問題を解決しました。

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    //Getting View which is touched.
    UIView *testView = [super hitTest:point withEvent:event];

    //If this is self. and point hitted on Masked Layer(Which is hiding our UIView).
    if(testView == self && testView.layer.mask != nil && CGPathContainsPoint([(CAShapedLayer*)testView.layer.mask path], NULL, point, false))
    {
            //Then return nil. So Touch thinks that UIView has not clicked. and touch is passed to UIView which is behind this view. And again hitTest is performed on inner UIViews.
            testView = nil;
    }

    //Return nil. So touch thinks that UIView is not clicked.
    //Return self. So touch thinks self is clicked. and no more hitTest is performed.
    return testView;
}

今、私はこの問題のためにIQIrregularViewと呼ばれるコントロールを実装しました。これをチェックして。

https://github.com/hackiftekhar/IQIrregularView

于 2013-03-17T08:16:56.350 に答える
0

ランダムな形のボタンを試す必要があります

GitHubにあるこのカスタム クラスでソリューションを見つけることができます

それは私のために働きました、そしてあなたのためにもうまくいくことを願っています....

ハッピーコーディング…………

于 2013-03-05T11:37:18.130 に答える