jjzjj

iphone - UIScrollView 做了滚动

coder 2024-01-15 原文

我想显示一张图片,该图片在页面上停留 5 秒,但每次我的 ScrollView 滚动时都会出现。所以显然我需要将 UILabel 的动画和 UIScrollView 的一些方法结合起来。老实说,我不确定该使用哪一个。此外,我在一个 UIViewController 上有两个 UIScrollView,所以我不知道应该将什么设置为委托(delegate)。

下面是我现在的动画

 [UIView animateWithDuration:0.3 animations:^{  // animate the following:
    pageCountImage.frame = CGRectMake(0, 0, 100, 50); // move to new location
}];

最佳答案

您的 View Controller 可以是两个 ScrollView 的委托(delegate)。同意@Ravi 的观点,您可以使用委托(delegate)参数来确定正在滚动的 ScrollView 。

听起来您需要打包一些动画才能使 UI 有意义:

// hide or show the page count image after a given delay, invoke completion when done
- (void)setPageCountImageHidden:(BOOL)hidden delay:(NSTimeInterval)delay completion:(void (^)(BOOL))completion {

    BOOL currentlyHidden = self.pageCountImage.alpha == 0.0;
    if (hidden == currentlyHidden) return;

    [UIView animateWithDuration:0.3 delay:delay options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        self.pageCountImage.alpha = (hidden)? 0.0 : 1.0;
    } completion:completion];
}

// move the page count image to the correct position given a scroll view content offset
- (void)positionPageControlForContentOffset:(CGFloat)xOffset {

    // assume page width is a constant (the width of a page in the scroll view)
    NSInteger page = xOffset / kPAGEWIDTH;

    // assume max page is a constant (the max number of pages in scroll view)
    // scroll positions in the "bounce" will generate page numbers out of bounds, fix that here...
    page = MAX(MIN(page, kMAXPAGE), 0);

    // kPAGE_INDICATOR_WIDTH the distance the page image moves between pages
    // kPAGE_INDICATOR_ORIGIN the page image x position at page zero
    CGFloat xPosition = kPAGE_INDICATOR_ORIGIN + page * kPAGE_INDICATOR_WIDTH;

    // assume y position and size are constants
    CGRect pageIndicatorFrame = CGRectMake(xPosition, kYPOS, kWIDTH, kHEIGHT);

    // finally, do the animation
    [UIView animateWithDuration:0.3 animations:^{
        self.pageCountImage.frame = pageIndicatorFrame;
    }];
}

然后在 View 中滚动:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    if (scrollView == /* the scroller with the page control */) {

        [self setPageCountImageHidden:NO delay:0.0 completion:^(BOOL finished) {
            [self positionPageControlForContentOffset:scrollView.contentOffset.x];
            [self setPageCountImageHidden:YES delay:5.0 completion:^(BOOL finished){}];
        }];
    }
    // and so on...

关于iphone - UIScrollView 做了滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12499444/

有关iphone - UIScrollView 做了滚动的更多相关文章

  1. ruby - 为什么 Ruby 返回 `str[-1..1]` 它做了什么? - 2

    假设我们有一个字符串str。如果str仅包含一个字符,例如str="1",则str[-1..1]返回1.但是如果str的size(length)比一个长,比如str="anythingelse",然后str[-1..1]返回""(空字符串)。为什么Ruby会这样解释字符串切片? 最佳答案 这种行为正是字符范围的工作方式。范围开始是-1,这是字符串中的最后一个字符。范围结束为1,即从开始算起的第二个位置。所以对于单字符字符串,这相当于0..1,也就是那个单个字符。对于双字符字符串,这是1..1,即第二个字符。对于三个字符的字符串,这是

  2. ruby-on-rails - expect() 在 rspec/cucumber 中做了什么? - 2

    在MichaelHartl的RailsTutorial中,许多示例使用expect()方法。这是cucumber步骤定义中的一个这样的例子:Then/^sheshouldseeherprofilepage$/doexpect(page).tohave_title(@user.name)end同样的例子可以写成同样的效果:Then/^sheshouldseeherprofilepage$/dopage.shouldhave_title(@user.name)end为什么要使用expect()?它增加了什么值(value)? 最佳答案

  3. ruby-on-rails - % 在下面的代码中做了什么? - 2

    我正在阅读“Rails3Way”,在第39页,它显示了匹配:to=>重定向方法的代码示例。在该方法中存在以下代码。虽然我知道模对数字有什么作用,但我不确定下面的%是做什么的,因为路径和参数显然都不是数字。如果有人能帮助我理解%在这种情况下的用法,我将不胜感激。proc{|params|path%params} 最佳答案 这可能是String#%与其他语言中的sprintf非常相似的方法:'%05d'%10#=>"00010"它可以接受单个参数或数组:'%.3f%s'%[10.341412,'samples']#=>"10.341sa

  4. ruby - Sinatra::Base.condition 实际上做了什么? - 2

    我遇到了sinatracondition方法,但对它的工作原理感到困惑。我有一段代码:defauthuserconditiondoredirect'/login'unlessuser_logged_in?endend它检查用户是否登录了某些路由,示例路由:get'/',:auth=>:userdoerb:indexenduser_logged_in?方法定义在项目lib目录下的帮助文件中:defuser_logged_in?ifsession[:user]@user=session[:user]return@userendreturnnilend所以,问题是:conditionbloc

  5. ruby - 绕过 Element 的方法无法滚动到 View 中 - Watir-webdriver with Ruby - 2

    因此,我们的页面中有以下代码:OnOff这是2个单选按钮。'开和关'。“关闭”是默认值。使用Watir-webdriver和Ruby,我们想要选择“打开”单选按钮。我们这样做:browser.radio(:id=>"HasRegistration_true").set但在这样做时,我们得到以下错误:`WebElement.clickElement':Elementcannotbescrolledintoview:[objectHTMLInputElement](Selenium::WebDriver::Error::MoveTargetOutOfBoundsError)我们知道Sele

  6. iphone - 扩展 restful_authentication/AuthLogic 以支持匿名 iPhone 的延迟登录的最佳方法是什么? - 2

    我正在构建一个与RubyonRails后端对话的iPhone应用程序。RubyonRails应用程序还将为Web用户提供服务。restful_authentication插件是提供快速和可定制的用户身份验证的绝佳方式。但是,我希望iPhone应用程序的用户在新列中存储一个由手机的唯一标识符([[UIDevicedevice]uniqueIdentifier])自动创建的帐户。稍后,当用户准备好创建用户名/密码时,帐户将更新为包含用户名和密码,iPhone唯一标识符保持不变。用户在设置用户名/密码之前不能访问该网站。然而,他们可以使用iPhone应用程序,因为该应用程序可以使用它的标识符

  7. iphone - 设计和 Rails 3 中的 http 身份验证 - 2

    我有一个使用deviseonrails3的应用程序。我想启用http身份验证,以便我可以从iPhone应用程序向我的网络应用程序进行身份验证。如何从我的iPhone应用程序进行身份验证以进行设计?这安全吗?还是我应该进行不同的身份验证? 最佳答案 从设计的角度来看,您有3个选择:1)使用基本的http身份验证:您的iPhone应用程序有一个secretkey-这是在您的iPhone应用程序代码中烘焙的-用于对网络应用程序的每个请求进行身份验证。Google搜索:“设计基本的http身份验证”2)您可以通过在您的iPhone应用程序中

  8. ruby-on-rails - .rewind 方法对 ruby​​ 中的 Tempfile 做了什么? - 2

    我已经查看了thesedocs和谷歌,似乎无法找到.rewind的目的,以及它与.close的区别,在使用Tempfile.另外,为什么.read在倒带前返回一个空字符串?这是一个例子:file=Tempfile.new('foo')file.path#=>AuniquefilenameintheOS'stempdirectory,#e.g.:"/tmp/foo.24722.0"#Thisfilenamecontains'foo'initsbasename.file.write("helloworld")file.rewindfile.read#=>"helloworld"file.c

  9. ruby - 如何使用 watir 滚动网页 - 2

    我正在尝试滚动网页以查找并单击滚动页面时延迟加载的内容。我正在使用以下命令require'watir-webdriver'@browser=Watir::new:firefox@browser.send_keys:space我在firefox上使用网络驱动程序,我在ubuntu上,但它不工作。在下面的ruby​​代码中,我试图向下滚动页面,直到找不到带有:id的元素。该元素正在延迟加载。几秒钟后我超时了,不知道下面的代码有什么问题。When/^deal(\d+)isloaded$/do|id|(0..5).eachdo|click|@browser.send_keys:spaceend

  10. Ruby:代码片段:(num & 1) == 0 究竟做了什么? - 2

    我正在观看来自PragProg的元编程视频,DaveThomas展示了这段代码:moduleMathclassfalseputsMath.is_even?2#=>true现在我明白这里发生了什么,但我不知道Math.is_even?的(num&1)部分究竟发生了什么?类方法。我知道这是一个按位运算,但仅此而已。有人可以向我解释那行代码是怎么回事吗?谢谢。 最佳答案 &是按位与运算符。执行(num&1)检查数字的最后一位(最低有效位)是否已设置。设置为奇数,不设置为偶数。这只是一种快速检查数字是偶数还是奇数的方法。您可以在此处查看ru

随机推荐