Jest我尝试以编程方式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];
}
Second.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];
我不明白为什么scrollView
无法在Second.m
中工作,但同样的代码工作在ViewControl.m.
我的Xcode Version 6.0.1
答案 0 :(得分:1)
请使用presentViewController
代替modalViewController
,并将UIScrollView
的代表设为SecondViewController
答案 1 :(得分:0)
检查以下步骤:
你是否符合你的第二堂课UIScrollViewDelegate
。
如果未设置,代码scroll.delegate=self;
将导致问题。