您的位置:首页 > 产品设计 > UI/UE

UIScroller的页面切换和上面的同步

2015-05-22 20:28 127 查看






1、点击上面的Button按钮,下面的界面随着改变

<span style="background-color: rgb(255, 255, 255);"><span style="color:#333333;">- (void)buttonAction6
{
self.button1.tintColor = kcolor1;
self.button2.tintColor = kcolor1;
self.button3.tintColor = kcolor1;
self.button4.tintColor = kcolor1;
self.button5.tintColor = kcolor1;
self.button6.tintColor = kcolor2;
self.button7.tintColor = kcolor1;
self.button8.tintColor = kcolor1;
self.button9.tintColor = kcolor1;</span></span>
<span style="background-color: rgb(255, 255, 255);"><span style="color:#333333;">// 设置此时的scrollview的对应偏移量
_scrollView.contentOffset = CGPointMake(kAllWidth * 5, 0);
}</span></span>

2、滑动下面的界面,让按钮的颜色对应改变

设置scrollView的代理,然后找到对应的方法,通过便宜到第几个,做出对应的处理,这里上调用对应的方法

// 设置scrollView滑动结束时,进行判断
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
// p 为偏移后是第几个view
NSInteger p = scrollView.contentOffset.x/scrollView.frame.size.width;
if (p == 0) {
[self buttonAction1];
}
else if (p == 1)
{
[self buttonAction2];
}
else if (p== 2)
{
[self buttonAction3];
}
else if (p == 3)
{
[self buttonAction4];
self.scrollViewTitle.contentOffset = CGPointMake(0, 0);
}
else if (p == 4)
{
[self buttonAction5];
self.scrollViewTitle.contentOffset = CGPointMake(160, 0);

}else if (p == 5)
{
[self buttonAction6];
}
else if (p == 6)
{
[self buttonAction7];
}
else if (p == 7)
{
[self buttonAction8];
}
else if (p == 8)
{
[self buttonAction9];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: