最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS實(shí)現(xiàn)多個(gè)垂直滑動(dòng)條并列視圖

 更新時(shí)間:2022年03月21日 11:22:12   作者:hzgisme  
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)多個(gè)垂直滑動(dòng)條并列視圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了iOS實(shí)現(xiàn)多個(gè)垂直滑動(dòng)條并列視圖的具體代碼,供大家參考,具體內(nèi)容如下

上一篇文章我們實(shí)現(xiàn)了一個(gè)垂直滑動(dòng)條的類 (VerticalSlider),用來滿足垂直滑動(dòng)的需求。那么這篇文章我們來把多個(gè)垂直滑動(dòng)條放到一起,可以在一個(gè)視圖上并排多個(gè)垂直滑動(dòng)條,也算是一個(gè)實(shí)際應(yīng)用的場(chǎng)景。

需求:

  • 同時(shí)展示多個(gè)垂直滑動(dòng)條
  • 每個(gè)滑動(dòng)條高度和視圖高度相同,隨視圖高度自動(dòng)變化
  • 所有滑動(dòng)條寬度相同,寬度為視圖寬度除以滑動(dòng)條個(gè)數(shù)
  • 根據(jù)提供的滑動(dòng)條的值更新視圖
  • 傳遞滑動(dòng)條的索引和值

需求還是比較簡(jiǎn)單的,自定義一個(gè)視圖 (UIView) 就可以實(shí)現(xiàn):

VerticalSliderDimmingView.h

//
// ?VerticalSliderDimmingView.h
//?
//
// ?Created by huang zhengguo on 2019/8/30.
// ?Copyright ? 2019 huang zhengguo. All rights reserved.
//
?
#import <UIKit/UIKit.h>
?
NS_ASSUME_NONNULL_BEGIN
?
typedef void (^SliderValueBlock) (NSInteger,float);
?
@interface VerticalSliderDimmingView : UIView
?
/**
?* 初始化手動(dòng)調(diào)光界面
?*
?* @param frame 大小
?* @param sliderCount 滑動(dòng)條個(gè)數(shù)
?* @param channelColors 滑動(dòng)條顏色
?* @param sliderTitle 滑動(dòng)條標(biāo)題
?* @param sliderValue 滑動(dòng)條值
?*
?*/
- (instancetype)initWithFrame:(CGRect)frame sliderCount:(NSInteger)sliderCount channelColors:(NSArray *)channelColors sliderTitles:(NSArray *)sliderTitle sliderValues:(NSArray *)sliderValue;
?
/**
?* 更新滑動(dòng)條
?*
?* @param sliderValueArray 所有通道顏色值
?*
?*/
- (void)updateSliderViewWith:(NSArray *)sliderValueArray;
?
/**
?* 更新滑動(dòng)條
?*
?* @param colorPercentValueArray 所有通道顏色百分比
?*
?*/
- (void)updateManualDimmingViewWithColorPercent:(NSArray *)colorPercentValueArray;
?
// 滑動(dòng)條滑動(dòng)
@property(nonatomic, copy) SliderValueBlock colorDimmingBlock;
?
// 滑動(dòng)條結(jié)束滑動(dòng)
@property(nonatomic, copy) SliderValueBlock colorDimmingEndBlock;
?
@end
?
NS_ASSUME_NONNULL_END

VerticalSliderDimmingView.m

//
// ?VerticalSliderDimmingView.m
//?
//
// ?Created by huang zhengguo on 2019/8/30.
// ?Copyright ? 2019. All rights reserved.
//
?
#import "VerticalSliderDimmingView.h"
#import "VerticalSlider.h"
?
@interface VerticalSliderDimmingView()
?
@property (strong, nonatomic) NSMutableArray *colorSliderArray;
?
@end
?
@implementation VerticalSliderDimmingView
?
- (NSMutableArray *)colorSliderArray {
? ? if (!_colorSliderArray) {
? ? ? ? _colorSliderArray = [NSMutableArray array];
? ? }
? ??
? ? return _colorSliderArray;
}
?
- (instancetype)initWithFrame:(CGRect)frame sliderCount:(NSInteger)sliderCount channelColors:(NSArray *)channelColors sliderTitles:(NSArray *)sliderTitle sliderValues:(NSArray *)sliderValue {
? ? if (self = [super initWithFrame:frame]) {
? ? ? ? self.translatesAutoresizingMaskIntoConstraints = NO;
? ? ? ??
? ? ? ? VerticalSlider *lastSlider = nil;
? ? ? ??
? ? ? ? [self.colorSliderArray removeAllObjects];
? ? ? ? for (int i=0; i<sliderCount; i++) {
? ? ? ? ? ? VerticalSlider *slider = [[VerticalSlider alloc] initWithFrame:CGRectZero title:[sliderTitle objectAtIndex:i] progressColor:[channelColors objectAtIndex:i] thumImage:@"control.png"];
? ? ? ? ? ??
? ? ? ? ? ? slider.minimumValue = MIN_LIGHT_VALUE;
? ? ? ? ? ? slider.maximumValue = MAX_LIGHT_VALUE;
? ? ? ? ? ? slider.translatesAutoresizingMaskIntoConstraints = NO;
? ? ? ? ? ? slider.tag = 20000 + i;
? ? ? ? ? ? slider.value = [sliderValue[i] integerValue] / 1000.0;
? ? ? ? ? ? slider.passValue = ^(float colorValue) {
? ? ? ? ? ? ? ? if (self.colorDimmingBlock) {
? ? ? ? ? ? ? ? ? ? self.colorDimmingBlock(slider.tag - 20000, colorValue * MAX_LIGHT_VALUE);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? };
? ? ? ? ? ??
? ? ? ? ? ? slider.passEndValue = ^(float colorValue) {
? ? ? ? ? ? ? ? // 傳遞結(jié)束滑動(dòng)時(shí)的顏色值
? ? ? ? ? ? ? ? if (self.colorDimmingEndBlock) {
? ? ? ? ? ? ? ? ? ? self.colorDimmingEndBlock(slider.tag - 20000, colorValue * MAX_LIGHT_VALUE);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? };
? ? ? ? ? ??
? ? ? ? ? ? [self addSubview:slider];
? ? ? ? ? ??
? ? ? ? ? ? if (i == 0) {
? ? ? ? ? ? ? ? [self setSliderConstraintsWithItem:slider toItem:self toItem:self isFirst:YES isLast:NO];
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? [self setSliderConstraintsWithItem:slider toItem:self toItem:lastSlider isFirst:NO isLast:NO];
? ? ? ? ? ? }
?
? ? ? ? ? ? // 處理最后一個(gè)
? ? ? ? ? ? if (i == sliderCount - 1) {
? ? ? ? ? ? ? ? [self setSliderConstraintsWithItem:slider toItem:self toItem:lastSlider isFirst:NO isLast:YES];
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? lastSlider = slider;
? ? ? ? ? ??
? ? ? ? ? ? [self.colorSliderArray addObject:slider];
? ? ? ? }
? ? }
? ??
? ? return self;
}
?
- (void)sliderTouchUpInSideAction:(UISlider *)slider {
? ? // 傳遞d結(jié)束滑動(dòng)時(shí)的顏色值
? ? if (self.colorDimmingEndBlock) {
? ? ? ? self.colorDimmingEndBlock(slider.tag - 20000, slider.value);
? ? }
}
?
#pragma mark --- 根據(jù)數(shù)據(jù)更新視圖
- (void)updateSliderViewWith:(NSArray *)sliderValueArray {
? ? // 刷新滑動(dòng)條
? ? for (int i=0;i<self.colorSliderArray.count;i++) {
? ? ? ? VerticalSlider *slider = [self.colorSliderArray objectAtIndex:i];
? ? ? ? slider.value = [sliderValueArray[i] floatValue] / 1000.0;
? ? }
}
?
#pragma mark --- 根據(jù)百分比更新視圖
- (void)updateManualDimmingViewWithColorPercent:(NSArray *)colorPercentValueArray {
? ? for (int i=0; i<colorPercentValueArray.count; i++) {
? ? ? ? UISlider *slider = [self.colorSliderArray objectAtIndex:i];
? ? ? ? slider.value = (float)[[colorPercentValueArray objectAtIndex:i] floatValue] * 10;
? ? }
}
?
#pragma mark --- 添加滑動(dòng)條約束
- (void)setSliderConstraintsWithItem:(nullable id)view1 toItem:(nullable id)view2 toItem:(nullable id)view3 isFirst:(BOOL)isFirst isLast:(BOOL)isLast {
? ? NSLayoutConstraint *sliderTopLayoutConstraint = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0];
? ? NSLayoutConstraint *sliderLeadingLayoutConstraint = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:view3 attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0];
? ? NSLayoutConstraint *sliderBottomLayoutConstraint = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
? ??
? ? if (!isFirst) {
? ? ? ? NSLayoutConstraint *sliderWithLayoutConstraint = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:view3 attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0];
? ? ? ??
? ? ? ? [self addConstraint:sliderWithLayoutConstraint];
? ? } else {
? ? ? ? sliderLeadingLayoutConstraint = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0];
? ? }
? ??
? ? // 最后一個(gè)
? ? if (isLast) {
? ? ? ? NSLayoutConstraint *sliderTrailingLayoutConstraint = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0];
? ? ? ??
? ? ? ? [self addConstraint:sliderTrailingLayoutConstraint];
? ? }
? ??
? ? [self addConstraints:@[sliderTopLayoutConstraint, sliderLeadingLayoutConstraint, sliderBottomLayoutConstraint]];
}
?
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
? ? // Drawing code
}
*/
?
@end

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

太保市| 玉树县| 湖州市| 容城县| 郧西县| 永修县| 佛冈县| 塘沽区| 吕梁市| 横山县| 长寿区| 镇康县| 仁布县| 定襄县| 新巴尔虎左旗| 攀枝花市| 石林| 奇台县| 卓尼县| 剑阁县| 洪江市| 盐边县| 东山县| 吉林市| 尖扎县| 清水河县| 芦溪县| 车险| 隆昌县| 会东县| 黑水县| 阿巴嘎旗| 拉萨市| 察隅县| 清涧县| 多伦县| 顺平县| 喀什市| 台湾省| 安平县| 左权县|