我正在使用https://github.com/cwRichardKim/RKSwipeBetweenViewControllers在我的控制器之间滑动。 每件事情都运行良好,我怎么想添加一个UIButton,我可以去另一个视图控制器(没有滑动。) 我从RKSwipeBetweenViewControllers导入了一个类,他们在下面的代码中使用它来创建一个uibutton
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(X_BUFFER+i*(self.view.frame.size.width-2*X_BUFFER)/numControllers-X_OFFSET, Y_BUFFER, (self.view.frame.size.width-2*X_BUFFER)/numControllers, HEIGHT)];
[navigationView addSubview:button];
[button addTarget:self action:@selector(tapSegmentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:[buttonText objectAtIndex:i] forState:UIControlStateNormal];
,选择器方法如下:
-(void)tapSegmentButtonAction:(UIButton *)button {
if (!self.isPageScrollingFlag) {
NSInteger tempIndex = self.currentPageIndex;
__weak typeof(self) weakSelf = self;
//%%% check to see if you're going left -> right or right -> left
if (button.tag > tempIndex) {
//%%% scroll through all the objects between the two points
for (int i = (int)tempIndex+1; i<=button.tag; i++) {
[pageController setViewControllers:@[[viewControllerArray objectAtIndex:i]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL complete){
//%%% if the action finishes scrolling (i.e. the user doesn't stop it in the middle),
//then it updates the page that it's currently on
if (complete) {
[weakSelf updateCurrentPageIndex:i];
}
}];
}
}
//%%% this is the same thing but for going right -> left
else if (button.tag < tempIndex) {
for (int i = (int)tempIndex-1; i >= button.tag; i--) {
[pageController setViewControllers:@[[viewControllerArray objectAtIndex:i]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:^(BOOL complete){
if (complete) {
[weakSelf updateCurrentPageIndex:i];
}
}];
}
}
}
}
现在,当我从视图控制器调用此方法时,它的响应方式与RKSwipeBetweenViewControllers中的方式不同。
现在,下面是我用来调用此选择器方法的代码。
[rkSwipeControllrObject tapSegmentButtonAction:myButtonObject];
答案 0 :(得分:0)
我希望你通过在RKSwipeBetweenViewControllers.h文件中声明这个方法来公开“tapSegmentButtonAction”方法。