整体开源源代码记录(滚动图片、滚动固定及贝塞尔曲线画突效果)

1:左右滚动多张图片实现

#import <UIKit/UIKit.h>

@protocol JZAlbumDelegate <NSObject>

@optional
-(void)didSelectedAlbumAtIndex:(NSInteger)index;

@end

@interface JZAlbumCell : UITableViewCell

@property(nonatomic, strong) NSArray *imgurlArray;/**< 图片URL */

@property(nonatomic, assign) id<JZAlbumDelegate> delegate;

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier frame:(CGRect)frame;

@end
#import "JZAlbumCell.h"
#import "UIImageView+WebCache.h"

@interface JZAlbumCell ()
{
    UIScrollView *_scrollView;
}

@end

@implementation JZAlbumCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier frame:(CGRect)frame{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //创建scrollview
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(5, 0, frame.size.width, frame.size.height)];
        _scrollView.showsHorizontalScrollIndicator = NO;
        [self addSubview:_scrollView];
        
        //添加图片
        for (int i = 0; i < 10; ++i) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((screen_width*2/5+5)*i, 5, screen_width*2/5, frame.size.height-10)];
            imageView.layer.masksToBounds = YES;
            imageView.layer.cornerRadius = 5;
//            [imageView setImage:[UIImage imageNamed:@"lesson_default"]];
            imageView.tag = i+20;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapImage:)];
            [imageView addGestureRecognizer:tap];
            imageView.userInteractionEnabled = YES;
            [_scrollView addSubview:imageView];
        }
        
    }
    return self;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setImgurlArray:(NSArray *)imgurlArray{
    _scrollView.contentSize = CGSizeMake((screen_width*2/5+5)*imgurlArray.count+5, _scrollView.frame.size.height);
    for (int i = 0; i < imgurlArray.count; i++) {
        UIImageView *imageView = (UIImageView *)[_scrollView viewWithTag:20+i];
        [imageView sd_setImageWithURL:[NSURL URLWithString:imgurlArray[i]] placeholderImage:[UIImage imageNamed:@"lesson_default"]];
    }
}

-(void)OnTapImage:(UITapGestureRecognizer *)sender{
    UIImageView *imageView = (UIImageView *)sender.view;
    int tag = (int)imageView.tag-20;
    [self.delegate didSelectedAlbumAtIndex:tag];
}


@end
            static NSString *cellIndentifier = @"courseCell1";
            JZAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
            if (cell == nil) {
                cell = [[JZAlbumCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier frame:CGRectMake(0, 0, screen_width, 90)];
                //下划线
                UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 89.5, screen_width, 0.5)];
                lineView.backgroundColor = separaterColor;
                [cell addSubview:lineView];
            }
            
            cell.delegate = self;
            [cell setImgurlArray:_albumImgurlArray];
            
            return cell;

效果图:

整体开源源代码记录(滚动图片、滚动固定及贝塞尔曲线画突效果)_第1张图片

 

2:红色view和蓝色view是添加在scrollView上的,向上拖动,红色view停留在屏幕顶端不动,其它的继续滚动,向下拖动后,红色view跟着下来

@interface ViewController () <UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@property (weak, nonatomic) IBOutlet UIView *blueView;

@property (weak, nonatomic) IBOutlet UIView *redView;

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.scrollView.contentSize = CGSizeMake(0, CGRectGetMaxY(self.blueView.frame));

}



- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    CGFloat imageH = self.imageView.frame.size.height;

    CGFloat offsetY = scrollView.contentOffset.y;

    if (offsetY >= imageH) {

        //将红色控件添加到控制器View中

        CGRect redFrame = self.redView.frame;

        redFrame.origin.y = 0;

        self.redView.frame = redFrame;

        [self.view addSubview:self.redView];

    }else {

        //将红色控件添加到控制器scrollView中

        CGRect redFrame = self.redView.frame;

        redFrame.origin.y = 140;

        self.redView.frame = redFrame;

        [self.scrollView addSubview:self.redView];

    }

  

    CGFloat scale = 1 - (offsetY / 20);

    scale = (scale >= 1) ? scale : 1;

    self.imageView.transform = CGAffineTransformMakeScale(scale, scale);

}

@end

3:通过贝塞尔曲线画突效果

#define SCREEN_WIDTH  ([UIScreen mainScreen].bounds.size.width)


@implementation CustomView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIView *myView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
        myView.backgroundColor=[UIColor redColor];
        [self addSubview:myView];
    }
    return self;
}


- (void)drawRect:(CGRect)rect
{
    UIColor *color = [UIColor redColor];
    [color set];  //设置线条颜色
    
    UIBezierPath* aPath = [UIBezierPath bezierPath];
    
    aPath.lineWidth = 5.0;
    aPath.lineCapStyle = kCGLineCapRound;  //线条拐角
    aPath.lineJoinStyle = kCGLineCapRound;  //终点处理
    
    [aPath moveToPoint:CGPointMake(SCREEN_WIDTH/2-50, 100)]; //左边点
    
    [aPath addQuadCurveToPoint:CGPointMake(SCREEN_WIDTH/2+50, 100) controlPoint:CGPointMake(SCREEN_WIDTH/2, 150)];  //右边点 中间点
    
    //[aPath stroke]; //只画线
    [aPath fill]; //填充
}

效果:

整体开源源代码记录(滚动图片、滚动固定及贝塞尔曲线画突效果)_第2张图片

你可能感兴趣的:(整体开源源代码记录(滚动图片、滚动固定及贝塞尔曲线画突效果))