【发布时间】:2013-02-06 20:17:35
【问题描述】:
我有两个 ViewController,“firstVC”和“secondVC”。 我想创建一个水平分页的滚动视图,保持两个视图控件分开:所以我创建了一个新的视图控制器“主页”,在其中创建滚动视图并添加 fisrtVC 和 secondVC。
-(void)viewDidLoad {
self.firstVC = [[firstVC alloc] initWithNibName:@"firstVC" bundle:nil];
self.secondVC = [[secondVC alloc] initWithNibName:@"secondVC" bundle:nil];
//setup frame
CGRect frame = self.scrollView.frame;
frame.origin.y = 0;
self.firstVC.view.frame = frame; //this is useless, I know... it's just for understand what I'm doing
frame.origin.x = 320;
self.secondVC.view.frame = frame;
//add the VC to the scrollView
[self.scrollview addSubview:self.firstVC.view];
[self.scrollview addSubview:self.secondVC.view];
//setup the scrollView
self.scrollView.contentSize = CGSizeMake(640 , frame.size.height);
self.scrollView.pagingEnabled = YES;
self.scrollView.showsHorizontalScrollIndicator = YES;
self.scrollView.userInteractionEnabled = YES;
self.scrollView.exclusiveTouch = YES;
self.scrollView.canCancelContentTouches = YES;
self.scrollView.delaysContentTouches = YES;
}
HomePage 在 UINavigationController 中; FirstVC 和 SecondVC 有更多的自定义(带图像)UIButton。 每个按钮都应该在 nagivationController 上推送一个新的 ViewController:为了做到这一点,FirstVC 和 SecondVC 对 HomePage 有一个弱引用,因此它们可以调用
[self.homePage.navigationController pushViewController:abc animated:YES];
一切正常,但我有两个问题:
1) 如果按钮与 IBAction 连接,但方法为空,当我按下按钮时,我可以看到突出显示的图片。 如果方法不为空(因为,当然,它必须做一些事情!)按钮立即调用该方法,所以没有高亮! 似乎不是在用户将手指从按钮上移开时调用该方法(因为它应该可以工作),而是在他触摸屏幕的那一刻。 我认为这个问题与第二个有关:
2)因此,滚动视图(从左到右,反之亦然)非常困难,因为很多时候它会调用与按钮相关的方法......
我想要的是类似于移动版 AppStore 的东西:例如,在“最畅销”中,您可以按下图标然后滚动视图。如果我尝试这样做,按钮会立即被按下!
【问题讨论】:
-
您为哪个按钮事件连接了 IBAction?
-
FirstVC 有 3 个按钮:每个按钮都有其 IBAction,它调用 [self.homepage.navigationController pushViewController:anotherVC animated:YES];。 secondVC 也是如此。
标签: iphone objective-c uiscrollview uibutton