文件名称:ios-仿网易新闻.zip
文件大小:513KB
文件格式:ZIP
更新时间:2022-07-31 12:19:22
其他
频道列表(UIScrollView)与新闻列表(UICollectionView)互相联动,而且频道文字有渐变效果。 关键代码及思路: 1、滚动新闻列表页,计算缩放比 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat offsetX = scrollView.contentOffset.x;// 偏移量 NSInteger idx = offsetX / self.view.width;// 浮点索引 CGFloat idx_float = offsetX / self.view.width;// 整形索引 CGFloat percent = idx_float - idx;// 百分比 NSInteger left_idx = idx;// 左边索引 NSInteger right_idx = idx 1;// 右边索引 CGFloat right_scale = percent;// 右边缩放比 CGFloat left_scale = 1 - percent;// 左边缩放比 ChannelLabel *leftLabel = _channelLabelArray[left_idx]; leftLabel.scale = left_scale; if(right_idx < _channelLabelArray.count) { ChannelLabel *rightLabel = _channelLabelArray[right_idx]; rightLabel.scale = right_scale; } } 2、通过缩放比,改变频道列表的Label的颜色和大小 - (void)setScale:(CGFloat)scale { _scale = scale; self.textColor = [UIColor colorWithRed:scale green:0 blue:0 alpha:1]; CGFloat minimumScale = 1.0; CGFloat maximumScale = 1.2; scale = minimumScale (maximumScale - minimumScale) * scale; self.transform = CGAffineTransformMakeScale(scale, scale); }