gpt4 book ai didi

ios - ScrollView 无法以编程方式工作

转载 作者:行者123 更新时间:2023-11-29 02:33:46 25 4
gpt4 key购买 nike

开玩笑,我尝试以编程方式ScrollView。它在 ViewController.m 中运行良好我试过这样

scroll=[[UIScrollView alloc]init];
scroll.frame=CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height);
scroll.delegate=self;
scroll.scrollEnabled=YES;
scroll.contentSize =CGSizeMake(100, 525);
scroll.backgroundColor=[UIColor yellowColor];
[self.view addSubview:scroll];

goo=[[UIButton alloc]init];
goo.frame=CGRectMake(0, 50, 100, 100);
goo.backgroundColor= [UIColor brownColor];
[goo setTitle:@"good Day" forState:UIControlStateNormal];
[goo addTarget:self action:@selector(ok:) forControlEvents:UIControlEventTouchDown];
[scroll addSubview:goo];

工作不错,但相同的代码在 SecondViewControl 中不起作用

-(void)ok:(id)sender
{
Second *second=[[Second alloc]initWithNibName:nil bundle:nil];
[second setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:second animated:YES completion:nil];

}

第二.m

scroll=[[UIScrollView alloc]init];
scroll.frame=CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height);
scroll.delegate=self;
scroll.scrollEnabled=YES;
scroll.contentSize =CGSizeMake(100, 525);
scroll.backgroundColor=[UIColor yellowColor];
[self.view addSubview:scroll];

我不明白为什么 scrollViewSecond.m 中不起作用,但相同的代码在 ViewControl.m 中起作用。我的 Xcode 版本 6.0.1

最佳答案

请使用presentViewController代替modalViewController并将UIScrollView的Delegate设置为SecondViewController

关于ios - ScrollView 无法以编程方式工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26601436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com