I'm working on a photo Collage application. I want to perform an action on image view so any one can help me to solve my problem. when i pick image from photo library and shown on image view after when double click on image view i want to push or present a new view to crop this image .....so anyone tell me what i do to solve my problem...
8 回答
使用自定义类型的 UIButton 并将图像放入其中。你完成了。
为 ImageView 添加手势
UITapGestureRecognizer *sg=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(HandleEvent)];
sg.numberOfTapsRequired=2;
[BottomBar addGestureRecognizer:sg];
[sg release];
并在这里完成您的任务:
-(void)HandleEvent
{
// your task
}
谢谢
You should use a UIButton instead of an UIImageView. You can set its style to custom and then asign it an image. UIButton provides all the methods for double tap already built in.
如果你使用 UIImageView 类,首先设置 setUserInteractionEnabled:YES 。然后将 UITapGestureRecognizer 事件设置为图像视图。
制作一个按钮,并清除它的颜色。在按钮的背面,放置您的图像视图,以便您的图像视图似乎可见而按钮不可见。现在将事件附加到按钮。
尝试这个
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint locationPoint = [[touches anyObject] locationInView:self.view];
CGPoint viewPoint = [imageView convertPoint:locationPoint fromView:self.view];
if ([imageView pointInside:viewPoint withEvent:event]) {
//do something
}
}
如果您使用的是 UIImageView,请确保使用setUserInteractionEnabled:YES
. 然后你需要在 touchesBegan,ended, (canceled) 中检查你的触摸。
您已设置好使用 UIImageView,您必须继承 UIImageView 并覆盖您想要拦截的触摸方法。例如:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Call super to make sure you don't lose any functionality
[super touchesBegan:touches withEvent:event];
// Perform the actions you want to perform with the tap.
}
使用 UIButtons 作为 UIImageViews 的替代品是一个好主意,您只需将连接从每个按钮拖到视图控制器中的插座并处理操作即可。您可以像当前使用 UIImageViews 一样在按钮上设置背景图像。将您的按钮类型设置为自定义,您会很好