【发布时间】:2011-11-24 07:12:21
【问题描述】:
可能重复:
How can i add more than 10 buttons on a navigationbar in iphone application development?
我想在包含八个按钮的导航栏上设置一个 UIScrollView,当我按下下一个或上一个按钮时,该导航栏还包含 leftbaritem 和 rightbaritem,然后滚动视图必须使用此按钮滚动,因为某些按钮会出现滚动视图框架。
到目前为止,我已经制作了滚动视图和按钮,但问题是按钮现在正在显示。任何人都可以通过提供示例或发送源代码来帮助我。
提前致谢
编辑
topToolBar = [UIToolbar new];
[topToolBar sizeToFit];
topToolBar.frame = CGRectMake(0,0, 280, 50);
topToolBar.barStyle = UIBarStyleBlackTranslucent;
segmentedControllerView = [[UIView alloc] initWithFrame:CGRectMake(5, 0, 280, 50)];
segmentedControllerView.clipsToBounds = YES;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(0,0, 60.0, segmentedControllerView.frame.size.height -10);
button.clipsToBounds = YES;
[segmentedControllerView addSubview:button];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button2 addTarget:self
action:@selector(aMethod2:)
forControlEvents:UIControlEventTouchDown];
[button2 setTitle:@"Show View2" forState:UIControlStateNormal];
button2.frame = CGRectMake(60,0, 60.0, segmentedControllerView.frame.size.height - 10);
[segmentedControllerView addSubview:button2];
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button3 addTarget:self
action:@selector(aMethod3:)
forControlEvents:UIControlEventTouchDown];
[button3 setTitle:@"Show View" forState:UIControlStateNormal];
button3.frame = CGRectMake(120,0, 60.0, segmentedControllerView.frame.size.height -10 );
[segmentedControllerView addSubview:button3];
UIButton *button4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button4 addTarget:self
action:@selector(aMethod4:)
forControlEvents:UIControlEventTouchDown];
[button4 setTitle:@"Show View" forState:UIControlStateNormal];
button4.frame = CGRectMake(180,0, 60.0, segmentedControllerView.frame.size.height -10 );
[segmentedControllerView addSubview:button4];
[topToolBar addSubview:segmentedControllerView];
self.navigationItem.titleView = topToolBar;
我也接近结果,但问题是当我按下下一个或上一个按钮时,它会移动到下一个或上一个按钮上,但它应该在视图下移动....
这是动画代码:
-(void)previousBarButtonAction{
[UIView beginAnimations: @"moveField"context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
segmentedControllerView.frame = CGRectMake(segmentedControllerView.frame.origin.x - 50,
segmentedControllerView.frame.origin.y,
segmentedControllerView.frame.size.width,
segmentedControllerView.frame.size.height);
[UIView commitAnimations];
}
-(void)nextBarButtonAction{
[UIView beginAnimations: @"moveField"context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
segmentedControllerView.frame = CGRectMake(segmentedControllerView.frame.origin.x + 50,
segmentedControllerView.frame.origin.y,
segmentedControllerView.frame.size.width,
segmentedControllerView.frame.size.height);
[UIView commitAnimations];
}
【问题讨论】:
-
这听起来像是对导航栏的可怕滥用。即使您设法通过了 Apple 的审核流程,我也强烈建议您不要这样做——它会混淆/惹恼您的用户。
-
我已经编辑了我的问题,请立即帮助我。
标签: iphone ios uiscrollview uitabbarcontroller uinavigationbar