我正在构建显示新闻文章的 iPhone 应用。
为了阅读一篇文章,我有一个带有 UITableView 的 View ,它显示文章的内容。
我需要什么: 我希望用户可以用手指滑动到下一篇文章,效果就像苹果的pageControl示例,或者像在图片之间滑动。(来回移动视觉效果)
问题: 唯一的方法是使用 UIScrollView 和“页面”, 或者有简单的方法包括检测滑动+操纵开关效果+推送 View Controller ?
我还想到的另一个方向是,如果我可以创建一个带有一个水平表格 View 的 View ,每个单元格将显示一篇文章,用户将滑动以移动到下一个单元格。
顺便说一句,iphone 的 fox news 应用程序有这个功能,但他们似乎使用“页面控制”解决方案。
任何信息都会有所帮助。
最佳答案
页面控制不是我认为的唯一解决方案。 想象一下,您必须在 viewController 中查看 View ,然后当您检测到滑动及其方向时, 你所要做的就是:
你就完成了...
这是一个例子:
// in your uiviewcontroller subclass
UIVIew *viewOne, *viewTwo;
-(void)swipeFromView:(UIVIew *)visibleView
toView:(UIView *)pushingView
direction:(UISwipeGestureRecognizerDirection)aDirection {
// assuming the content of pushingView already set
CGPoint visibleViewCenter = [visibleView center]; // register the center
CGRect visibleViewFrame = [visibleView frame];
CGPoint pushingViewCenter, visibleViewNewCenter;
visibleViewNewCenter.y = visibleViewCenter.y;
pushingViewCenter.y = visibleViewCenter.y;
// I use 2 here, but you would make more calculations
pushingViewCenter.x = 2 * visibleViewFrame.width;
visibleViewNewCenter.x = -1 * 2 * visibleViewFrame.width;
// reversing x if direction is right
if(aDirection == UISwipeGestureRecognizerDirectionRight) {
pushingViewCenter.x *= -1;
visibleViewNewCenter.x *= -1;
}
// once the tmp center for pushingView is calculated
// set it, and run the animation
[pushingView setCenter:pushingViewCenter];
[UIVIew animateWithDuration:theDurationYouWant
animations:^{
[visibleView setCenter:visibleViewNewCenter];
[pushingView setCenter:visibleViewCenter];
}];
}
// somewhere else, you handle the swipe
-(void)handleSwipeGesture:(UISwipeGestureRecognizer *)sender {
// set content, etc
[self swipeFromView:viewOne toView:viewTwo direction:[sender direction]];
}
希望这对您有所帮助。
关于iphone - 通过滑动切换 View 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6562016/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我正在从erb文件切换到HAML。我将hamlgem添加到我的系统中。我创建了app/views/layouts/application.html.haml文件。我应该只删除application.html.erb文件吗?此外,仍然有/public/index.html文件被呈现为默认页面。我想创建自己的默认index.html.haml页面。我应该把它放在哪里以及如何使系统呈现该文件而不是默认索引文件?谢谢! 最佳答案 是的,您可以删除任何已转换为HAML的View的ERB版本。至于你的另一个问题,删除public/index/h