iphone - 如何在用户滚动 TextView 后启用按钮

标签 iphone objective-c ios

我正在尝试做这样的事情:首先,在启动时,“接受”按钮被禁用,用户必须通读 TextView 区域中的条款和条件,然后接受按钮将被启用。 到目前为止,这是我的代码,任何人都可以给我一些建议吗?

- (IBAction)acceptAction:(id)sender {
    if ([self.termConditionTextView scrollsToTop] == true) {
        [acceptButtonOutlet setEnabled:NO];
        [[[UIAlertView alloc] initWithTitle:@"Term & Condition" message:@"Please read term &    condition first. Thank you." delegate:nil cancelButtonTitle:@"Back" otherButtonTitles:nil] show];
    } else {
        [acceptButtonOutlet setEnabled:YES];
    }
}

最佳答案

创建按钮时,设置 myButton.enabled = NO

为 ScrollView 设置 UIScrollViewDelegate

然后实现scrollViewDidScroll委托(delegate)函数。在该函数中,检查您的 ScrollView 的内容偏移量以查看是否已到达底部。像这样:

- (void)scrollViewDidScroll: (UIScrollView*)scrollView
{
    float scrollViewHeight = scrollView.frame.size.height;
    float scrollContentSizeHeight = scrollView.contentSize.height;
    float scrollOffset = scrollView.contentOffset.y;

    if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
    {
        myButton.enabled = YES;
    }
}

关于iphone - 如何在用户滚动 TextView 后启用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11942143/

相关文章:

ios - NSMutableArray 保存所有 View 的所有值

ios - 使用 setViewControllers 时,viewWillAppear、viewDidAppear 和 viewWillDisappear 不会在 iOS 5 上被调用

ios - 无法切换回原始 View

ios - iPad 版 iOS App

iphone - 使用 phonegap 在 iPhone 上应用程序速度慢

objective-c - 在 UIScrollView 的容器 View 的坐标系中确定 UIScrollView 的 subview 框架

ios - 如何设置容器 View 以交换两个 child

ios - Xcode 7 UI 测试与 Xcode Bot 的集成效果如何?它是否显示 UI 测试步骤?

ios - 如何布局单行 Collection View ?

iphone - 使用 .xib 文件是最佳做法吗?