OC基础之推荐一个旋转木马(跑马灯)效果的图片展示Demo

这个旋转木马(跑马灯)效果的图片展示Demo,包括设定旋转方向,图片倒影,背景设置,旋转速度,开始结束,点击显示选中的图片,彩色的块展示等等功能

效果图:(源码下载:https://github.com/hbblzjy/OC-CarrouselDemo)


部分代码展示:

- (void)testCarrouselView
{
    NSMutableArray *array = [NSMutableArray array];
    for (NSInteger i = 0; i < 8; i ++)
    {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"mm%ld.jpeg", (long)i]];
        [array addObject:image];
    }
    LYCarrouselView *carr = [[LYCarrouselView alloc] initWithFrame:CGRectMake(20, 80, 280, 160) images:array callback:^(NSInteger index, NSInteger event) {
        
        NSLog(@"%ld %@", index, event == 1 ? @"点击" : @"长按");
    }];
    [carr addImage:[UIImage imageNamed:@"mm8.jpeg"]];
    carr.backgroundColor = [UIColor blackColor];
    carr.animationSpeed = 2;
    carr.showReflectLayer = YES;
    [self.view addSubview:carr];
    
    UIButton *start = [UIButton buttonWithType:UIButtonTypeCustom];
    [start setFrame:CGRectMake(40, 260, 100, 48)];
    [start setTitle:@"开始" forState:UIControlStateNormal];
    [start setBackgroundColor:[UIColor blueColor]];
    [start handleControlEvents:UIControlEventTouchUpInside withBlock:^(UIControlEvents events) {
        
        //默认为向左,如果暂停了,修改方向,开始向右
        [carr startRotateRight:YES];
    }];
    [self.view addSubview:start];
    
    
    UIButton *stop = [UIButton buttonWithType:UIButtonTypeCustom];
    [stop setFrame:CGRectMake(180, 260, 100, 48)];
    [stop setTitle:@"停止" forState:UIControlStateNormal];
    [stop setBackgroundColor:[UIColor blueColor]];
    [stop handleControlEvents:UIControlEventTouchUpInside withBlock:^(UIControlEvents events) {
        
        [carr stopRotate];
    }];
    [self.view addSubview:stop];
    
    LYSlider *slopex = [[LYSlider alloc] initWithWidth:280 center:CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height - 120) horizontal:YES];
    [self.view addSubview:slopex];
    slopex.thumbcolor = [UIColor magentaColor];
    slopex.gradientBackInfo = [self sliderBackGraidentInfo];
    slopex.value = 2 / 6.0;
    [slopex handleSliderAction:UIControlEventValueChanged callback:^(LYSlider *slider, UIControlEvents event) {
        
        carr.animationSpeed = slider.value * 6;
    }];
}
视图.h文件内容:
- (NSDictionary *)sliderBackGraidentInfo
{
    return @{@"locations" : @[@(0),
                              @(60 / 360.),
                              @(120 / 360.),
                              @(180 / 360.),
                              @(240 / 360.),
                              @(300 / 360.),
                              @(1)],
             @"colors" : @[[UIColor redColor],
                           [UIColor yellowColor],
                           [UIColor greenColor],
                           [UIColor cyanColor],
                           [UIColor blueColor],
                           [UIColor magentaColor],
                           [UIColor redColor]]};
}


// index: view/image tag;   event:(1 tap, 2 long press)
typedef void(^CarrouselBlock)(NSInteger index, NSInteger event);

// 旋转木马
@interface LYCarrouselView : UIView

@property (nonatomic, assign) BOOL canAutoRotate;// 自动动画开关
@property (nonatomic, assign) CGFloat sensitivity;// 滑动灵敏度 默认为1 越大越灵敏 0无效 正负影响方向
@property (nonatomic, assign) NSTimeInterval minimumPressTime;// 长按最短时间 超过则视为长按 默认为0.4
@property (nonatomic, assign) CGFloat animationSpeed;//默认为3.0 转过一张图时间

@property (nonatomic, assign) BOOL showReflectLayer;//是否显示倒影层

- (LYCarrouselView *)initWithFrame:(CGRect)frame images:(NSArray *)images callback:(CarrouselBlock)block;

- (void)addImage:(UIImage *)image;

- (void)startRotateRight:(BOOL)right; // 开始动画 (right:是否向右) canAutoRotate=YES
- (void)stopRotate; //停止动画 canAutoRotate=NO


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hbblzjy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值