【问题标题】:UIScrollView isn't working with Auto-layout and SegueUIScrollView 不适用于自动布局和 Segue
【发布时间】:2013-05-23 18:08:15
【问题描述】:

在 ViewController(主体)中,我有一个称为滚动器的 UiSrcollView。当我启动应用程序时效果很好。但是,如果我使用 segue(传递给另一个视图控制器),当我返回主体时,uiscrollview 停止工作。

ps.:我使用自动布局

有人!?请。 我尝试在 viewDidLoad 和 viewDidApper 中实现内容大小。

(void)viewDidLoad{
     [super viewDidLoad];
    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(320, 2000)];
     scroller.contentSize = CGSizeMake(320, 2000);
}


(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [scroller setScrollEnabled:YES];
    scroller.contentSize = CGSizeMake(320, 2000);
}

【问题讨论】:

    标签: uiscrollview segue autolayout viewdidload viewdidappear


    【解决方案1】:

    尝试在 viewDidLayoutSubviews 中设置它,例如:

    (void)viewDidLayoutSubviews {
        [scroller setScrollEnabled:YES];
        scroller.contentSize = CGSizeMake(320, 2000);
    }
    

    【讨论】:

    • Thnaks.. 太棒了!但是当我回到第一个 ViewController 时,滚动条重新启动到顶部!.. 谢谢
    • 我认为您需要将滚动位置存储在 prepareForSegue 中并在 viewWillAppear 中设置滚动位置以保持滚动位置。
    猜你喜欢
    • 2013-01-04
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-28
    • 1970-01-01
    • 2013-08-23
    • 2016-04-01
    相关资源
    最近更新 更多