2013-02-26 2 views
1

현재 콜라주 앱을 위해 노력 중입니다. 콜라주 프레임을 그려야하고 그 후에 카메라 롤 또는 카메라에서 이미지를 추가해야합니다. 다음 유형보기가 필요합니다. enter image description here모양이 다른 여러 imageView를 추가하는 방법은 무엇입니까?

5 개의 UIImageViews를 추가했습니다. 모양으로 그리려면 내가 좋아하는 UIBezierPath 추가 한이 나는 모든 5에 대해 수행 한 그러나 그 프레임이 다른 네 개의 이미지 뷰에 오버랩하는 때문에 imageView5 터치를 추가 한 후 다른 4 개보기에 감지되지처럼 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]; 

합니다.

그래서 이것을 설계하는 방법이 없습니다. 터치 액션으로 모든 이미지 뷰에 이미지를 추가해야합니다.

도와주세요. 누군가가 이것에 대해 어떤 생각을 가지고 있다면 공유하십시오.

감사의 말 전진.

예 2는 다음과 같습니다. Insta Collage app. enter image description here

+0

는 왜 행동뿐만 아니라 button.You이 배경 이미지를 사용 해달라고? –

+0

버튼을 사용하면 imageview5 만 버튼 동작을 수행합니다. – deepti

+0

구현하려는 정확한 이미지 디자인을 공유 할 수 있습니까? 이 프레임은 동일한 목표를 달성하기위한 몇 가지 대안을 보여줍니다. 귀하의 필요에 따라, –

답변

0

당신은 임의 모양의 단추

을 시도해야 당신이 GitHub

그것은 나를 위해 일한 희망도 당신을 위해 작동에 발견이 사용자 정의 클래스의 솔루션을 찾을 수 있습니다

....

해피 코딩 ...........

+0

클릭 할 수 있습니다. OBShapedButton. 내 대답을 시도하면 모든 조건에서 작동합니다. –

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

관련 문제