Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 选择以编程方式显示在UIScrollView中的当前按钮_Ios_Objective C_Cocoa Touch_Uiscrollview - Fatal编程技术网

Ios 选择以编程方式显示在UIScrollView中的当前按钮

Ios 选择以编程方式显示在UIScrollView中的当前按钮,ios,objective-c,cocoa-touch,uiscrollview,Ios,Objective C,Cocoa Touch,Uiscrollview,我有一个启用分页的UIScrollView。每一页我都有一个按钮。我希望每次滑动都会选中UIScrollView中显示的按钮 我猜解决方案将基于 -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate 但是,如果没有过多的范围和偏移计算,我怎么知道显示的是哪个按钮呢 谢谢最简单的方法是从UIScrollView中为每个UIButton设置一个与页码+1(+1)相等的标记

我有一个启用分页的UIScrollView。每一页我都有一个按钮。我希望每次滑动都会选中
UIScrollView
中显示的按钮

我猜解决方案将基于

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
但是,如果没有过多的范围和偏移计算,我怎么知道显示的是哪个按钮呢


谢谢

最简单的方法是从UIScrollView中为每个UIButton设置一个与页码+1(+1)相等的标记,因为对于页面0,标记将为1,所有默认标记都为0,因此您可以找到该按钮)。然后,您可以根据需要,在
viewdidenddeclaring/viewdicrosoll
或其他滚动视图委托方法中计算标记。我在
viewdidenddeclaring
中进行所有计算,如下所示:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    int page = scrollView.contentOffset.x / scrollView.frame.size.width;
    //now you have the current page so you can get the button 
    UIButton *button =(UIButton *) [scrollView viewWithTag:page+1]; //the +1 that I was talking about above
   button.selected = YES;
}
此外,您可能希望取消选择其他按钮,以便也可以通过以下标记找到它们:

for(int i = 1; i<=numberOfPages; i++) { 
     UIButton *button =(UIButton *) [scrollView viewWithTag:i];
     button.selected = NO;
  }

for(int i=1;i您可以使用
ui页面控件获取当前页面,并从
视图获取所有
子视图
?您想在当前页面或新页面中选择按钮吗?我有5个页面。当我在滑动结束时从第3页滑动到第4页时,我想选择\按下第4页上的按钮。