整體開源原始碼記錄(滾動圖片、滾動固定及貝茲路徑畫突效果),貝塞爾

來源:互聯網
上載者:User

整體開源原始碼記錄(滾動圖片、滾動固定及貝茲路徑畫突效果),貝塞爾

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;

 

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]; //填充}

效果:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.