2013-02-26 61 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

相关问题