Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部分功能的修复以及添加 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified VITimelineViewDemo/Source/Convenient/VIRangeView+Creator.h
100644 → 100755
Empty file.
Empty file modified VITimelineViewDemo/Source/Convenient/VIRangeView+Creator.m
100644 → 100755
Empty file.
Empty file modified VITimelineViewDemo/Source/Convenient/VITimelineView+Creator.h
100644 → 100755
Empty file.
Empty file modified VITimelineViewDemo/Source/Convenient/VITimelineView+Creator.m
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file modified VITimelineViewDemo/Source/Utils/CachedAssetImageGenerator.h
100644 → 100755
Empty file.
Empty file modified VITimelineViewDemo/Source/Utils/CachedAssetImageGenerator.m
100644 → 100755
Empty file.
22 changes: 18 additions & 4 deletions VITimelineViewDemo/Source/Utils/UIView+ConstraintHolder.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +34,16 @@ static const char VIConstaintsKey = 'c';
- (NSArray<NSLayoutConstraint *> *)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;
Expand All @@ -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];
}
Expand Down
Empty file modified VITimelineViewDemo/Source/Utils/VIAutoScroller.h
100644 → 100755
Empty file.
Empty file modified VITimelineViewDemo/Source/Utils/VIAutoScroller.m
100644 → 100755
Empty file.
Empty file modified VITimelineViewDemo/Source/Utils/VIDisplayTriggerMachine.h
100644 → 100755
Empty file.
Empty file modified VITimelineViewDemo/Source/Utils/VIDisplayTriggerMachine.m
100644 → 100755
Empty file.
15 changes: 15 additions & 0 deletions VITimelineViewDemo/Source/VIRangeContentView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,23 @@
#import <UIKit/UIKit.h>
@import CoreMedia;

@class VIRangeContentView;

@protocol VIVideoRangeContentViewDataSource <NSObject>

- (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<VIVideoRangeContentViewDataSource> dataSource;

- (void)reloadData;
- (void)updateDataIfNeed;

Expand Down
Empty file modified VITimelineViewDemo/Source/VIRangeContentView.m
100644 → 100755
Empty file.
Empty file modified VITimelineViewDemo/Source/VIRangeEarView.h
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions VITimelineViewDemo/Source/VIRangeEarView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Empty file modified VITimelineViewDemo/Source/VIRangeView.h
100644 → 100755
Empty file.
3 changes: 1 addition & 2 deletions VITimelineViewDemo/Source/VIRangeView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ - (instancetype)initWithCoder:(NSCoder *)coder
}

- (void)commonInit {
_contentHeight = 45;
_contentHeight = 50;
_widthPerSecond = 50;
_startTime = kCMTimeZero;
_endTime = kCMTimeZero;
Expand Down Expand Up @@ -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],
Expand Down
3 changes: 3 additions & 0 deletions VITimelineViewDemo/Source/VITimelineView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
91 changes: 73 additions & 18 deletions VITimelineViewDemo/Source/VITimelineView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "VITimelineView.h"
#import "UIView+ConstraintHolder.h"

#import "VIRangeContentAssetImageDataSource.h"
@interface VITimelineView() <VIRangeViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<VIRangeView *> *)rangeViews {
Expand All @@ -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],
Expand All @@ -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 =
Expand All @@ -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;
Expand Down Expand Up @@ -341,6 +395,7 @@ - (void)removeRangeViewAtIndex:(NSInteger)index animated:(BOOL)animated completi

}


- (CGFloat)timelineWidthPerSeconds {
return self.contentWidthPerSecond;
}
Expand Down
12 changes: 1 addition & 11 deletions VITimelineViewDemo/Source/VIVideoRangeContentView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,12 @@

@class VIVideoRangeContentView;

@protocol VIVideoRangeContentViewDataSource <NSObject>

- (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<VIVideoRangeContentViewDataSource> dataSource;

@property (nonatomic) CGSize imageSize;
@property (nonatomic) NSInteger preloadCount;

Expand Down
Empty file modified VITimelineViewDemo/Source/VIVideoRangeContentView.m
100644 → 100755
Empty file.
Empty file modified VITimelineViewDemo/ViewController.h
100644 → 100755
Empty file.
27 changes: 23 additions & 4 deletions VITimelineViewDemo/ViewController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "VITimelineView+Creator.h"
#import "VIRangeView+Creator.h"

@interface ViewController () <VIRangeViewDelegate, VITimelineViewDelegate>


{
VITimelineView *timelineView;
}
@end

@implementation ViewController
Expand All @@ -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];
Expand All @@ -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;
Expand Down