您好
我已经使用 Xcode 有一段时间了,并且现在使用了很多次 UIGestureRecognizers
。目前我正在开发一个需要轮播的 iPad 应用程序,所以有什么比使用 iCarousel 更好,因为我已经遇到过它,我认为它很棒。
我在向轮播项目添加 UISwipeGestureRecognizer
时遇到了一些问题(我会用它来删除“刷过”项目)。看起来很容易,但看起来 UIGestureRecognizer
不存在,但如果打印 view.recognizer 我可以看到它实际上存在。我错过了什么?
对于任何语言错误,我们深表歉意!
代码
- (UIView *)carouseliCarousel *)carousel viewForItemAtIndexNSUInteger)index reusingViewUIView *)view
{
UILabel *nameLabel = nil;
UILabel *notesLabel = nil;
UIImageView *icon1 = nil;
UIImageView *icon2 = nil;
Notebook *referenceNotebook = [_notebookArray objectAtIndex:index];
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250.0f, 373.0f)];
((UIImageView *)view).image = [UIImage imageNamed"notebookBase"];
view.contentMode = UIViewContentModeCenter;
CGPoint startingPoint = view.frame.origin;
CGSize startingSize = view.frame.size;
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(startingPoint.x, startingPoint.y + 60, startingSize.width, 100)];
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.textAlignment = NSTextAlignmentCenter;
nameLabel.font = [FontController useFontKlinic_Light:50];
nameLabel.tag = 1;
[view addSubview:nameLabel];
notesLabel = [[UILabel alloc]initWithFrame:CGRectMake(startingPoint.x, startingPoint.y + 95, startingSize.width, 100)];
notesLabel.backgroundColor = [UIColor clearColor];
notesLabel.textAlignment = NSTextAlignmentCenter;
notesLabel.font = [FontController useFontKlinic_Light:30];
[view addSubview:notesLabel];
icon1 = [[UIImageView alloc] initWithFrame:CGRectMake(startingPoint.x + 105, startingPoint.y + 18, 40, 40)];
icon1.image = [UIImage imageNamed"notebookIcon1"];
[view addSubview:icon1];
icon2 = [[UIImageView alloc] initWithFrame:CGRectMake(startingPoint.x + 105, startingPoint.y + 320, 40, 40)];
icon2.image = [UIImage imageNamed"notebookIcon1"];
[view addSubview:icon2];
//UIView *swipeView = [[UIView alloc] initWithFrame:CGRectMake(startingPoint.x, startingPoint.y, startingSize.width, startingSize.height)];
//swipeView.backgroundColor = [UIColor clearColor];
//UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(carouselSwipewipeHandler];
//[swipeRecognizer setDirectionUISwipeGestureRecognizerDirectionUp)];
// [swipeView addGestureRecognizer:swipeRecognizer];
//[view addSubview:swipeView];
}
else
{
//get a reference to the label in the recycled view
nameLabel = (UILabel *)[view viewWithTag:1];
}
nameLabel.text = referenceNotebook.name;
notesLabel.text = @"n note";
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(carouselSwipewipeHandler];
[swipeRecognizer setDirectionUISwipeGestureRecognizerDirectionUp)];
[view addGestureRecognizer:swipeRecognizer];
view.tag = index;
NSLog(@"gesture recogs: %@", view.gestureRecognizers);
return view;
}
有人知道我做错了什么吗?
这也是 iCarousel 文档的链接:
https://github.com/nicklockwood/iCarousel#detecting-taps-on-item-views
提前致谢!
默认情况下,任何时候只能激活一种手势,并且轮播在内部使用一种手势进行滚动。因此,如果您想使用其他手势,您需要为您的手势和轮播手势添加一个代理,以便您可以使它们工作 simultaneously .
关于ios - 向 iCarousel 项目添加自定义手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23315676/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |