UIScrollView 内的 UIButton 禁用滚动 [英] UIButton inside UIScrollView disables scrolling

查看:40
本文介绍了UIScrollView 内的 UIButton 禁用滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将按钮拖到我的滚动视图后,窗口不再滚动!如果我删除按钮,现在可以滚动.

After dragging a button to my scrollview, the window no longer scrolls! If I remove the button, scrolling now works.

有人遇到过这个问题吗?

Anyone run into this issue before?

//ScrollViewController.h
@property (weak, nonatomic) IBOutlet UIScrollView *scroller;


//ScrollViewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self.scroller setScrollEnabled:YES];
    [self.scroller setContentSize:CGSizeMake(320, 700)];
}

推荐答案

其实就是把代码移动到viewDidLayoutSubiews后才起作用.

Actually, it just worked after adding moving the code to viewDidLayoutSubiews.

有人能解释一下为什么会这样吗?

Can someone explain WHY this works?

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [self.scroller setScrollEnabled:YES];
    [self.scroller setContentSize:CGSizeMake(320, 700)];
}

这篇关于UIScrollView 内的 UIButton 禁用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆