实际上有四个按钮,每个按钮都有子按钮。单击第一个按钮,第二个按钮必须通过为子按钮提供空间向下移动,但即使在设置滚动视图后它也不起作用。
bgsroll=[[UIScrollView alloc]init];
bgsroll.frame=CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
bgsroll.userInteractionEnabled=YES;
bgsroll.scrollEnabled=YES;
// bgsroll.backgroundColor=[UIColor grayColor];
bgsroll.showsVerticalScrollIndicator=YES;
bgsroll.contentSize=CGSizeMake(200, 2000);
[self.view addSubview:bgsroll];
happyBtn=[[UIButton alloc]init];
happyBtn.frame=CGRectMake(MainView.frame.size.width*0.12, MainView.frame.size.height*0.1, CGRectGetWidth(self.view.frame)/1.5, 40);
[happyBtn setTitle:@"Happiness" forState:UIControlStateNormal];
[happyBtn setBackgroundColor:[UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f]];
[happyBtn addTarget:self action:@selector(tapHappy:) forControlEvents:UIControlEventTouchUpInside];
[bgsroll addSubview:happyBtn];
happyView=[[UIView alloc]init];
happyView.frame=CGRectMake(MainView.frame.size.width*0.26,CGRectGetHeight(happyBtn.frame)*2.2, CGRectGetWidth(MainView.frame)/1.6, CGRectGetHeight(MainView.frame)/3);
happyView.layer.cornerRadius=8.0;
happyView.layer.borderWidth=0.5;
happyView.layer.borderColor=[[UIColor blueColor]CGColor];
[bgsroll addSubview:happyView];
LettingGo=[[UIButton alloc]init];
LettingGo.frame=CGRectMake(happyView.frame.size.width*0.01,happyView.frame.size.height*0.1, CGRectGetWidth(happyView.frame)/1.05, 50);
[LettingGo setTitle:@"Letting go of negativity" forState:UIControlStateNormal];
LettingGo.titleLabel.numberOfLines=2;
LettingGo.titleLabel.adjustsFontSizeToFitWidth=YES;
[LettingGo setBackgroundColor:[UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f]];
[happyView addSubview:LettingGo];
LivingPresent=[[UIButton alloc]init];
LivingPresent.frame=CGRectMake(happyView.frame.size.width*0.01,LettingGo.frame.size.height*1.4, CGRectGetWidth(happyView.frame)/1.05, 40);
[LivingPresent setTitle:@"Living in the present" forState:UIControlStateNormal];
LivingPresent.titleLabel.adjustsFontSizeToFitWidth=YES;
[LivingPresent setBackgroundColor:[UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f]];
[happyView addSubview:LivingPresent];
happyView.hidden=YES;
CreateBtn=[[UIButton alloc]init];
CreateBtn.frame=CGRectMake(MainView.frame.size.width*0.12, MainView.frame.size.height*0.5, CGRectGetWidth(self.view.frame)/1.5, 40);
[CreateBtn setTitle:@"Happiness" forState:UIControlStateNormal];
[CreateBtn setBackgroundColor:[UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f]];
[CreateBtn addTarget:self action:@selector(tapHappy:) forControlEvents:UIControlEventTouchUpInside];
[bgsroll addSubview:CreateBtn];
-(void)tapHappy:(id)selector{
happyView.hidden=!happyView.hidden;
}
答案 0 :(得分:0)
不工作意味着按下按钮时不滚动?我发现滚动元素更容易创建一个通过动画更改子视图中元素坐标的方法。像这样:
- (void)viewDidLoad {
expandButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
[expandButton1 addTarget:self action:@selector(expandButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)expandButtonPressed:(id)sender{
if (expanded == NO) {
expanded = YES;
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionRepeat animations:^{
[UIView setAnimationRepeatCount:1];
image1.frame = CGRectMake(image1.frame.origin.x, image1.frame.origin.y+200.0f, image1.frame.size.width, image1.frame.size.height);
image.frame2 = CGRectMake(image2.frame.origin.x, image2.frame.origin.y+200.0f, image2.frame.size.width, image2.frame.size.height);
expandButton2.frame = CGRectMake(expandButton2.frame.origin.x, expandButton2.frame.origin.y+200.0f, expandButton2.frame.size.width, expandButton2.frame.size.height);
expandButton3.frame = CGRectMake(expandButton3.frame.origin.x, expandButton3.frame.origin.y+200.0f, expandButton3.frame.size.width, expandButton3.frame.size.height);
}completion:nil];
}