我需要在用户滑动 uicollectionview 时执行特定操作。 我以每个单元格捕获全屏的方式构建它。
我试过那些方法:
A. scrollViewDidEndDecelerating
# pragma UIScrollView
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSLog(@"detecting scroll");
for (UICollectionViewCell *cell in [_servingTimesCollectionView visibleCells]) {
NSIndexPath *indexPath = [_servingTimesCollectionView indexPathForCell:cell];
CGPoint scrollVelocity = [scrollView.panGestureRecognizer velocityInView:_servingTimesCollectionView];
if (scrollVelocity.x > 0.0f)
NSLog(@"going right");
else if (scrollVelocity.x < 0.0f)
NSLog(@"going left");
}
}
但是 scrollVelocity 返回 null。正在调用该方法。
B. UISwipeGestureRecognizer
在委托(delegate)给 UICollectionViewDataSource 和 UIGestureRecognizerDelegate 的 UIViewController 的 ViewDidLoad 中,我添加了:
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)];
swipeRight.numberOfTouchesRequired = 1;
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeft:)];
swipeRight.numberOfTouchesRequired = 1;
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[_servingTimesCollectionView addGestureRecognizer:swipeRight];
[_servingTimesCollectionView addGestureRecognizer:swipeLeft];
以及 UiViewController 中的以下内容:
#pragma mark - UISwipeGestureRecognizer Action
-(void)didSwipeRight: (UISwipeGestureRecognizer*) recognizer {
NSLog(@"Swiped Right");
}
-(void)didSwipeLeft: (UISwipeGestureRecognizer*) recognizer {
NSLog(@"Swiped Left");
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
NSLog(@"Asking permission");
return YES;
}
但没有一个被调用。
怎么了?我正在为 ios7 开发
最佳答案
您没有设置手势的委托(delegate):
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)];
swipeRight.delegate = self;
swipeRight.numberOfTouchesRequired = 1;
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeft:)];
swipeLeft.delegate = self;
swipeLeft.numberOfTouchesRequired = 1;
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
关于iphone - 在 UICollectionView 中检测滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19232485/
如何在Ruby的if语句中检查bash命令的返回值(true/false)。我想要这样的东西,if("/usr/bin/fswscell>/dev/null2>&1")has_afs="true"elsehas_afs="false"end它会提示以下错误含义,它总是返回true。(irb):5:warning:stringliteralincondition正确的语法是什么?更新:/usr/bin/fswscell寻找afs安装和运行状态。它会抛出这样的字符串,Thisworkstationbelongstocell如果afs没有运行,命令以状态1退出 最
这是我在ChefRecipe中的一blockRuby:#ifdatadirdoesn'texist,moveoverthedefaultoneif!File.exist?("/vol/postgres/data")execute"mv/var/lib/postgresql/9.1/main/vol/postgres/data"end结果是:Executingmv/var/lib/postgresql/9.1/main/vol/postgres/datamv:inter-devicemovefailed:`/var/lib/postgresql/9.1/main'to`/vol/post
我正在尝试检索以base64编码格式接收的图像的内容类型和文件名。这是使用base64编码图像执行POST请求的代码require'net/http'require"rubygems"require'active_support'url=URI.parse('http://localhost:3000/')image=ActiveSupport::Base64.encode64(open("public/images/rails.png").to_a.join)post_params={'image'=>image}Net::HTTP.post_form(url,post_params
我目前正在学习RoR,我想我一定是误解了什么。我有一个ActiveRecord类调用User,对:name和:email进行简单验证,例如presence:true、length:{maximum:15}等。我想我会在控制台中检查验证。我进入Rails控制台(开发环境),并创建一个名称太长的新实例,例如user_instance=User.new(名称:“aaaaabbbbbcccccdddddd”,电子邮件:“”)。验证不会抛出任何错误。当我尝试user_instance.save时,记录不会写入数据库,所以在那个阶段它显然工作正常。我做错了什么? 最佳答
我知道一些检查参数是否为零的方法ifparam[:some_value]ifparam[:some_value].present?if!param[:some_value].nil?#unlessparam[:some_value].nil?if!param[:some_value].blank?#unlessparam[:some_value].blank?哪一个是正确的并且最受欢迎?它们之间有什么区别?我宁愿使用ifparam[:some_value]因为它最简单也最短。 最佳答案 以下是nil?、blank?和present?
假设我有一个如下所示的数组:a=[cat,dog,cat,mouse,rat,dog,cat]我如何循环遍历它,并对重复项进行处理-例如说删除它们?换句话说,如果我执行了a.eachdo|i|,我将如何针对a[1]、a[2]、a[3]评估a[0]。..然后当我找到我想要的那个时,说a[2]在这种情况下有第一个副本,然后我将它插入堆栈或删除它或其他东西。我知道如何评估键和值...但是我如何在同一个数组中评估值?谢谢。 最佳答案 您可以创建一个散列来存储任何元素重复的次数。因此只遍历数组一次。h=Hash.new(0)['a','b',
我正在构建一个与RubyonRails后端对话的iPhone应用程序。RubyonRails应用程序还将为Web用户提供服务。restful_authentication插件是提供快速和可定制的用户身份验证的绝佳方式。但是,我希望iPhone应用程序的用户在新列中存储一个由手机的唯一标识符([[UIDevicedevice]uniqueIdentifier])自动创建的帐户。稍后,当用户准备好创建用户名/密码时,帐户将更新为包含用户名和密码,iPhone唯一标识符保持不变。用户在设置用户名/密码之前不能访问该网站。然而,他们可以使用iPhone应用程序,因为该应用程序可以使用它的标识符
我找不到任何关于这是否可能的信息,但它会很有用及时思考。例如,我试图找出其中哪一个更快:[val2,val3,val4,val5,val6].find{|x|x!=val1}[val2,val3,val4,val5,val6].all?{|x|x==val1}有这样的东西吗?[val2,val3,val4,val5,val6].find{|x|x!=val1}.performance 最佳答案 有!而且您甚至不需要Rails。查看benchmark来自标准库。作为示例:require'benchmark'putsBenchmark.
我试图通过在Ruby中进行的查询从MongoDB获取字段的子集,但它似乎不起作用。它不返回任何结果这是ruby代码:coll.find("title"=>'Halo',:fields=>["title","isrc"])#thisdoesn'twork如果我删除字段散列,它会工作,返回包含所有字段的结果coll.find("title"=>'Halo')#thisworks查看mongodb控制台,第一个查询在mongodb服务器上结束,如下所示:{title:"Halo",fields:["title","isrc"]}如果我尝试从mongo客户端控制台进行查询,它会工作,我会得到结
我有一个使用deviseonrails3的应用程序。我想启用http身份验证,以便我可以从iPhone应用程序向我的网络应用程序进行身份验证。如何从我的iPhone应用程序进行身份验证以进行设计?这安全吗?还是我应该进行不同的身份验证? 最佳答案 从设计的角度来看,您有3个选择:1)使用基本的http身份验证:您的iPhone应用程序有一个secretkey-这是在您的iPhone应用程序代码中烘焙的-用于对网络应用程序的每个请求进行身份验证。Google搜索:“设计基本的http身份验证”2)您可以通过在您的iPhone应用程序中