[英]Creating Photo library like iPhone, but UIImage tap event handler not working
Hi i am new to iOS programming. 嗨,我是iOS编程的新手。 I need to create an photo library like iPhone native photo app. 我需要创建一个像iPhone本机照片应用程序一样的照片库。 I have found a library MWPhotoBrowser that provides nearly same UI for photo browsing and its perfect for my requirement. 我找到了一个MWPhotoBrowser库,该库提供几乎相同的UI用于照片浏览,并且非常适合我的需求。 But now i have 2 problems 但是现在我有两个问题
First is that i need to create a grid layout with thumbnails. 首先,我需要使用缩略图创建网格布局。 Clicking on an thumbnail should display image in full screen with browsing functionality. 单击缩略图应以浏览功能全屏显示图像。 I tried to dynamically adding UIImageViews
in UIScrollView
, but UIScrollView is not scrolling and images are going out of screen. 我试图在UIScrollView
动态添加UIImageViews
,但是UIScrollView不能滚动并且图像不在屏幕上。
Second is i could not get any tap handler on UIImageView
so that i can open an image in full screen. 其次是我无法在UIImageView
上获得任何点击处理程序,因此我可以全屏打开图像。 Looking for some tips here, i am really stuck here. 在这里寻找一些提示,我真的被困在这里。
You can give a shot to this library, it has both features which you are looking for. 您可以试一试这个库,它具有您要查找的两个功能。
https://github.com/gdavis/FGallery-iPhone https://github.com/gdavis/FGallery-iPhone
Hope it helps :) 希望能帮助到你 :)
For ScrollView scrolling issue you have to increase scrlViewMain.contentSize
dynamically. 对于ScrollView滚动问题,您必须动态增加scrlViewMain.contentSize
。 Create a for
loop and put bellow code at the end of loop. 创建一个for
循环并将下面的代码放在循环的末尾。
scrlViewMain.contentSize = CGSizeMake(0, incermentAsPerYourNeed);
For the tapping issue you have to add TapGesture
. 对于点击问题,您必须添加TapGesture
。 Put bellow code when your ImageView
creates. 创建ImageView
时放入下面的代码。
imgView.tag = giveAsPerYourRecordsID;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[imgView addGestureRecognizer:tap];
[tap release];
And bellow your catch method for tapping. 然后按一下您的捕获方法进行攻丝。
- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer {
UIImageView *tmpImgView = (UIImageView *)gestureRecognizer.view;
}
I have also developed similar functionality a few days ago for my project. 几天前,我还为我的项目开发了类似的功能。 For tap issue you should use UIButton
instead of UIImageView
, it gives you tap action event. 对于点击问题,您应该使用UIButton
而不是UIImageView
,它为您提供了点击动作事件。 For Scrollview not scrolling, just make sure you update contentSize property of UIScrollView
, otherwise it would not scroll according to your subviews. 对于Scrollview不滚动,只需确保更新UIScrollView
contentSize属性,否则它不会根据您的子视图滚动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.