2013-02-26 98 views
1

目前我工作的拼貼應用程序。我想繪製拼貼畫框,然後我需要從相機膠捲或相機中添加圖像。我需要以下類型視圖 enter image description here如何添加具有不同形狀的多個imageView?

我已經添加了5個UIImageViews。要繪製的形狀我已經加入UIBezierPath像imageview1

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觸摸後,因爲它的框架上其他四個ImageView的overlaping是不是對所有其他4次檢測。

所以我沒有得到如何設計這一點。我需要通過觸摸操作將圖像添加到所有圖像。

請幫幫我。如果有人對此有任何想法,請分享。

在此先感謝。

以下是實施例2這是從的Insta拼貼應用enter image description here

+0

爲什麼不使用button.You有背景圖片以及動作? – 2013-02-26 12:09:02

+0

如果我將使用按鈕則只有imageview5會做按鈕操作。 – deepti 2013-02-26 12:13:41

+0

可以請你分享,你要實現的具體形象設計?這個框架顯示了實現相同的幾個選擇。對於特定於您的需求,發佈鏈接 – 2013-02-26 12:13:50

回答

0

你應該嘗試任意形狀的按鈕

你可以找到在GitHub

它爲我工作,希望會爲你工作,也發現了這個自定義類解決方案....

快樂編碼...........

+0

有可能點擊的機會OBShapedButton。如果你嘗試我的答案,它會適用於所有情況。 – 2013-07-17 05:41:39

3

我已經通過重寫則hitTest解決了這個問題:withEvent:方法UIView的方法。

- (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

相關問題