diff --git a/VITimelineViewDemo/Source/Convenient/VIRangeView+Creator.h b/VITimelineViewDemo/Source/Convenient/VIRangeView+Creator.h old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/Convenient/VIRangeView+Creator.m b/VITimelineViewDemo/Source/Convenient/VIRangeView+Creator.m old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/Convenient/VITimelineView+Creator.h b/VITimelineViewDemo/Source/Convenient/VITimelineView+Creator.h old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/Convenient/VITimelineView+Creator.m b/VITimelineViewDemo/Source/Convenient/VITimelineView+Creator.m old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/DataSource/VIRangeContentAssetImageDataSource.h b/VITimelineViewDemo/Source/DataSource/VIRangeContentAssetImageDataSource.h old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/DataSource/VIRangeContentAssetImageDataSource.m b/VITimelineViewDemo/Source/DataSource/VIRangeContentAssetImageDataSource.m old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/Utils/CachedAssetImageGenerator.h b/VITimelineViewDemo/Source/Utils/CachedAssetImageGenerator.h old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/Utils/CachedAssetImageGenerator.m b/VITimelineViewDemo/Source/Utils/CachedAssetImageGenerator.m old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/Utils/UIView+ConstraintHolder.h b/VITimelineViewDemo/Source/Utils/UIView+ConstraintHolder.h old mode 100644 new mode 100755 index 72b2969..e15d230 --- a/VITimelineViewDemo/Source/Utils/UIView+ConstraintHolder.h +++ b/VITimelineViewDemo/Source/Utils/UIView+ConstraintHolder.h @@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)setVi_constraints:(NSArray *)constraints; - (NSArray *)vi_constraints; +- (NSLayoutConstraint *)getConstraint:(NSLayoutAttribute)attibute; + - (void)updateConstraintWithAttribute:(NSLayoutAttribute)attribute maker:(NSLayoutConstraint *(^)(void))maker; - (void)updateLeftConstraint:(NSLayoutConstraint *(^)(void))maker; - (void)updateRightConstraint:(NSLayoutConstraint *(^)(void))maker; @@ -32,6 +34,16 @@ static const char VIConstaintsKey = 'c'; - (NSArray *)vi_constraints { return objc_getAssociatedObject(self, &VIConstaintsKey); } +- (NSLayoutConstraint *)getConstraint:(NSLayoutAttribute)attibute { + NSLayoutConstraint *constraint; + for (NSLayoutConstraint *c in self.vi_constraints) { + if (c.firstItem == self && c.firstAttribute == attibute) { + constraint = c; + break; + } + } + return constraint; +} - (void)updateConstraintWithAttribute:(NSLayoutAttribute)attribute maker:(NSLayoutConstraint *(^)(void))maker { NSLayoutConstraint *constraint; @@ -41,21 +53,23 @@ static const char VIConstaintsKey = 'c'; break; } } - [NSLayoutConstraint deactivateConstraints:@[constraint]]; - + if (constraint) { + [NSLayoutConstraint deactivateConstraints:@[constraint]]; + } NSMutableArray *mutableConstraints = [self.vi_constraints mutableCopy]; [mutableConstraints removeObject:constraint]; - if (maker) { NSLayoutConstraint *newConstraint = maker(); if (newConstraint.firstItem == self && newConstraint.firstAttribute == attribute) { - [mutableConstraints addObject:constraint]; + [mutableConstraints addObject:newConstraint]; [NSLayoutConstraint activateConstraints:@[newConstraint]]; } } self.vi_constraints = mutableConstraints; } + + - (void)updateLeftConstraint:(NSLayoutConstraint *(^)(void))maker { [self updateConstraintWithAttribute:NSLayoutAttributeLeft maker:maker]; } diff --git a/VITimelineViewDemo/Source/Utils/VIAutoScroller.h b/VITimelineViewDemo/Source/Utils/VIAutoScroller.h old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/Utils/VIAutoScroller.m b/VITimelineViewDemo/Source/Utils/VIAutoScroller.m old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/Utils/VIDisplayTriggerMachine.h b/VITimelineViewDemo/Source/Utils/VIDisplayTriggerMachine.h old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/Utils/VIDisplayTriggerMachine.m b/VITimelineViewDemo/Source/Utils/VIDisplayTriggerMachine.m old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/VIRangeContentView.h b/VITimelineViewDemo/Source/VIRangeContentView.h old mode 100644 new mode 100755 index 0df297c..f67a907 --- a/VITimelineViewDemo/Source/VIRangeContentView.h +++ b/VITimelineViewDemo/Source/VIRangeContentView.h @@ -9,8 +9,23 @@ #import @import CoreMedia; +@class VIRangeContentView; + +@protocol VIVideoRangeContentViewDataSource + +- (NSInteger)videoRangeContentViewNumberOfImages:(VIRangeContentView *)view; +- (UIImage *)videoRangeContent:(VIRangeContentView *)view imageAtIndex:(NSInteger)index preferredSize:(CGSize)size; + +@optional + +- (BOOL)videoRangeContent:(VIRangeContentView *)view hasCacheAtIndex:(NSInteger)index; + +@end + @interface VIRangeContentView : UIView +@property (nonatomic, strong) id dataSource; + - (void)reloadData; - (void)updateDataIfNeed; diff --git a/VITimelineViewDemo/Source/VIRangeContentView.m b/VITimelineViewDemo/Source/VIRangeContentView.m old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/VIRangeEarView.h b/VITimelineViewDemo/Source/VIRangeEarView.h old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/VIRangeEarView.m b/VITimelineViewDemo/Source/VIRangeEarView.m old mode 100644 new mode 100755 index 6ca78e4..e482c28 --- a/VITimelineViewDemo/Source/VIRangeEarView.m +++ b/VITimelineViewDemo/Source/VIRangeEarView.m @@ -43,6 +43,7 @@ - (void)commonInit { [imageView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES; [imageView.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES; + } - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { diff --git a/VITimelineViewDemo/Source/VIRangeView.h b/VITimelineViewDemo/Source/VIRangeView.h old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/Source/VIRangeView.m b/VITimelineViewDemo/Source/VIRangeView.m old mode 100644 new mode 100755 index 2451682..be88289 --- a/VITimelineViewDemo/Source/VIRangeView.m +++ b/VITimelineViewDemo/Source/VIRangeView.m @@ -61,7 +61,7 @@ - (instancetype)initWithCoder:(NSCoder *)coder } - (void)commonInit { - _contentHeight = 45; + _contentHeight = 50; _widthPerSecond = 50; _startTime = kCMTimeZero; _endTime = kCMTimeZero; @@ -201,7 +201,6 @@ - (void)setContentHeight:(CGFloat)contentHeight { - (void)setContentInset:(UIEdgeInsets)contentInset { _contentInset = contentInset; - [NSLayoutConstraint deactivateConstraints:self.contentContainerView.vi_constraints]; self.contentContainerView.vi_constraints = @[[self.contentContainerView.leftAnchor constraintEqualToAnchor:self.leftEarView.rightAnchor], diff --git a/VITimelineViewDemo/Source/VITimelineView.h b/VITimelineViewDemo/Source/VITimelineView.h old mode 100644 new mode 100755 index 5964888..e6b9d2c --- a/VITimelineViewDemo/Source/VITimelineView.h +++ b/VITimelineViewDemo/Source/VITimelineView.h @@ -46,6 +46,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)scrollToEndOfRangeView:(VIRangeView *)rangeView animated:(BOOL)animated completion:(nullable void(^)(void))completion; - (void)scrollToContentOffset:(CGPoint)contentOffset animated:(BOOL)animated completion:(void(^)(void))completion; + + + - (CGFloat)calculateOffsetXAtTime:(CMTime)time; - (NSInteger)getRangeViewIndexAtTime:(CMTime)time; - (CMTime)calculateTimeAtOffsetX:(CGFloat)offsetX; diff --git a/VITimelineViewDemo/Source/VITimelineView.m b/VITimelineViewDemo/Source/VITimelineView.m old mode 100644 new mode 100755 index 9772d03..de63675 --- a/VITimelineViewDemo/Source/VITimelineView.m +++ b/VITimelineViewDemo/Source/VITimelineView.m @@ -8,7 +8,7 @@ #import "VITimelineView.h" #import "UIView+ConstraintHolder.h" - +#import "VIRangeContentAssetImageDataSource.h" @interface VITimelineView() @property (nonatomic, strong) UIScrollView *scrollView; @@ -75,7 +75,14 @@ - (void)commonInit { scrollContentView.translatesAutoresizingMaskIntoConstraints = NO; [scrollView addSubview:scrollContentView]; self.scrollContentView = scrollContentView; - + + + scrollView.userInteractionEnabled = YES; + UIPinchGestureRecognizer * pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAct:)]; + [scrollView addGestureRecognizer:pinch]; + UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAct:)]; + [scrollView addGestureRecognizer:longPress]; + UIView *scrollRangeContentView = [UIView new]; scrollRangeContentView.translatesAutoresizingMaskIntoConstraints = NO; [scrollContentView addSubview:scrollRangeContentView]; @@ -103,7 +110,7 @@ - (void)commonInit { [scrollRangeContentView.leftAnchor constraintEqualToAnchor:scrollContentView.leftAnchor].active = YES; [scrollRangeContentView.rightAnchor constraintEqualToAnchor:scrollContentView.rightAnchor].active = YES; [scrollRangeContentView.centerYAnchor constraintEqualToAnchor:scrollContentView.centerYAnchor].active = YES; - [scrollRangeContentView.heightAnchor constraintEqualToConstant:45].active = YES; + [scrollRangeContentView.heightAnchor constraintEqualToConstant:50].active = YES; [contentBackgroundView.leftAnchor constraintEqualToAnchor:self.leftAnchor].active = YES; [contentBackgroundView.rightAnchor constraintEqualToAnchor:self.rightAnchor].active = YES; @@ -174,6 +181,45 @@ - (void)tapRangeViewAction:(UITapGestureRecognizer *)gesture { } } +- (void)pinchAct:(UIPinchGestureRecognizer *)gesture { + if (gesture.state == UIGestureRecognizerStateBegan) {} + else if (gesture.state == UIGestureRecognizerStateChanged) { + + [self.rangeViews enumerateObjectsUsingBlock:^(VIRangeView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + + obj.widthPerSecond = obj.widthPerSecond * gesture.scale; + + VIRangeContentAssetImageDataSource * dataSource = obj.contentView.dataSource; + dataSource.widthPerSecond = obj.widthPerSecond; + [obj.contentView reloadData]; + }]; + + gesture.scale = 1; + } else if (gesture.state == UIGestureRecognizerStateEnded){ + gesture.scale = 1; + + } +} +- (void)longPressAct:(UILongPressGestureRecognizer *)gesture { + if (gesture.state == UIGestureRecognizerStateBegan) { + [self.rangeViews enumerateObjectsUsingBlock:^(VIRangeView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + obj.widthPerSecond =50.0f/CMTimeGetSeconds(CMTimeSubtract(obj.endTime, obj.startTime)); + [obj.contentView reloadData]; + }]; + } + else if (gesture.state == UIGestureRecognizerStateChanged) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ +// [self exChangeSelectRangeViewIndex:0 needMoveRangeViewIndex:1]; + }); + + } else if (gesture.state == UIGestureRecognizerStateEnded){ + [self.rangeViews enumerateObjectsUsingBlock:^(VIRangeView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + obj.widthPerSecond = 50; + [obj.contentView reloadData]; + }]; + } + +} #pragma mark - Public - (void)reloadWithRangeViews:(NSArray *)rangeViews { @@ -200,24 +246,23 @@ - (void)insertRangeView:(VIRangeView *)view atIndex:(NSInteger)index { ]; [NSLayoutConstraint activateConstraints:view.vi_constraints]; } else { - void(^updateLeft)(VIRangeView *rangeView) = ^(VIRangeView *rangeView) { - [rangeView updateRightConstraint:^NSLayoutConstraint * _Nonnull{ - CGFloat offset = rangeView.contentInset.right + view.contentInset.left - (self.rangeViewLeftInset + self.rangeViewRightInset); - NSLayoutConstraint *rightConstraint = [rangeView.rightAnchor constraintEqualToAnchor:view.leftAnchor constant:offset]; - return rightConstraint; - }]; - }; + void(^updateRight)(VIRangeView *rangeView) = ^(VIRangeView *rangeView) { - [rangeView updateRightConstraint:^NSLayoutConstraint * _Nonnull{ + [rangeView updateLeftConstraint:^NSLayoutConstraint * _Nonnull{ return nil; }]; }; if (index >= self.rangeViews.count) { VIRangeView *leftRangeView = self.rangeViews.lastObject; - updateLeft(leftRangeView); - + CGFloat offset = leftRangeView.contentInset.right + view.contentInset.left - (self.rangeViewLeftInset + self.rangeViewRightInset); + __weak typeof(leftRangeView) weakLeftRView = leftRangeView; + __weak typeof(view) weakView = view; + [leftRangeView updateRightConstraint:^NSLayoutConstraint * _Nonnull{ + NSLayoutConstraint *rightConstraint = [weakLeftRView.rightAnchor constraintEqualToAnchor:weakView.leftAnchor constant:offset]; + return rightConstraint; + }]; view.vi_constraints = @[[view.rightAnchor constraintEqualToAnchor:self.scrollRangeContentView.rightAnchor], [view.topAnchor constraintEqualToAnchor:self.scrollRangeContentView.topAnchor], @@ -237,13 +282,21 @@ - (void)insertRangeView:(VIRangeView *)view atIndex:(NSInteger)index { ]; [NSLayoutConstraint activateConstraints:view.vi_constraints]; } else { + VIRangeView *leftRangeView = self.rangeViews[index - 1]; VIRangeView *rightRangeView = self.rangeViews[index]; - - updateLeft(leftRangeView); - - updateRight(rightRangeView); - + + CGFloat offsetl = leftRangeView.contentInset.right + view.contentInset.left - (self.rangeViewLeftInset + self.rangeViewRightInset); + __weak typeof(leftRangeView) weakLeftRView = leftRangeView; + __weak typeof(view) weakView = view; + [leftRangeView updateRightConstraint:^NSLayoutConstraint * _Nonnull{ + NSLayoutConstraint *rightConstraint = [weakLeftRView.rightAnchor constraintEqualToAnchor:weakView.leftAnchor constant:offsetl]; + return rightConstraint; + }]; + [rightRangeView updateLeftConstraint:^NSLayoutConstraint * _Nonnull{ + return nil; + }]; + CGFloat offset = (rightRangeView.contentInset.left + view.contentInset.right) - (self.rangeViewLeftInset + self.rangeViewRightInset); view.vi_constraints = @@ -270,6 +323,7 @@ - (void)removeCurrentActivedRangeViewCompletion:(void(^)(void))completion { } } + - (void)removeRangeViewAtIndex:(NSInteger)index animated:(BOOL)animated completion:(void(^)(void))completion { if (index < 0 || index >= self.rangeViews.count) { return; @@ -341,6 +395,7 @@ - (void)removeRangeViewAtIndex:(NSInteger)index animated:(BOOL)animated completi } + - (CGFloat)timelineWidthPerSeconds { return self.contentWidthPerSecond; } diff --git a/VITimelineViewDemo/Source/VIVideoRangeContentView.h b/VITimelineViewDemo/Source/VIVideoRangeContentView.h old mode 100644 new mode 100755 index 59934fa..0982ad6 --- a/VITimelineViewDemo/Source/VIVideoRangeContentView.h +++ b/VITimelineViewDemo/Source/VIVideoRangeContentView.h @@ -12,22 +12,12 @@ @class VIVideoRangeContentView; -@protocol VIVideoRangeContentViewDataSource - -- (NSInteger)videoRangeContentViewNumberOfImages:(VIVideoRangeContentView *)view; -- (UIImage *)videoRangeContent:(VIVideoRangeContentView *)view imageAtIndex:(NSInteger)index preferredSize:(CGSize)size; - -@optional - -- (BOOL)videoRangeContent:(VIVideoRangeContentView *)view hasCacheAtIndex:(NSInteger)index; - -@end @interface VIVideoRangeContentView : VIRangeContentView @property (nonatomic, strong) NSOperationQueue *loadImageQueue; -@property (nonatomic, strong) id dataSource; + @property (nonatomic) CGSize imageSize; @property (nonatomic) NSInteger preloadCount; diff --git a/VITimelineViewDemo/Source/VIVideoRangeContentView.m b/VITimelineViewDemo/Source/VIVideoRangeContentView.m old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/ViewController.h b/VITimelineViewDemo/ViewController.h old mode 100644 new mode 100755 diff --git a/VITimelineViewDemo/ViewController.m b/VITimelineViewDemo/ViewController.m old mode 100644 new mode 100755 index 0b9782d..bcecdcd --- a/VITimelineViewDemo/ViewController.m +++ b/VITimelineViewDemo/ViewController.m @@ -9,10 +9,13 @@ #import "ViewController.h" #import #import "VITimelineView+Creator.h" +#import "VIRangeView+Creator.h" @interface ViewController () - +{ + VITimelineView *timelineView; +} @end @implementation ViewController @@ -26,10 +29,10 @@ - (void)viewDidLoad { NSURL *url2 = [[NSBundle mainBundle] URLForResource:@"water" withExtension:@"mp4"]; AVAsset *asset2 = [AVAsset assetWithURL:url2]; - CGFloat widthPerSecond = 40; - CGSize imageSize = CGSizeMake(30, 45); + CGFloat widthPerSecond = 50; + CGSize imageSize = CGSizeMake(50, 50); - VITimelineView *timelineView = + timelineView = [VITimelineView timelineViewWithAssets:@[asset1, asset2] imageSize:imageSize widthPerSecond:widthPerSecond]; @@ -55,6 +58,22 @@ - (void)viewDidLoad { obj.backgroundView.backgroundColor = [UIColor colorWithRed:0.72 green:0.73 blue:0.77 alpha:1.00]; }]; } +- (IBAction)addins:(id)sender { + NSURL *url2 = [[NSBundle mainBundle] URLForResource:@"water" withExtension:@"mp4"]; + CGSize imageSize = CGSizeMake(30, 45); + AVAsset * asset = [AVAsset assetWithURL:url2]; + VIRangeView * rangeView = [VIRangeView imageRangeViewWithAsset:asset imageSize:imageSize]; + [timelineView insertRangeView:rangeView atIndex:2]; + [timelineView.rangeViews enumerateObjectsUsingBlock:^(VIRangeView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + obj.clipsToBounds = YES; + obj.layer.cornerRadius = 4; + obj.leftEarView.backgroundColor = [UIColor colorWithRed:0.72 green:0.73 blue:0.77 alpha:1.00]; + obj.rightEarView.backgroundColor = [UIColor colorWithRed:0.72 green:0.73 blue:0.77 alpha:1.00]; + obj.backgroundView.backgroundColor = [UIColor colorWithRed:0.72 green:0.73 blue:0.77 alpha:1.00]; + }]; +} + + - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent;