diff --git a/SAVideoRangeSlider/SAVideoRangeSlider.m b/SAVideoRangeSlider/SAVideoRangeSlider.m index 2dff742..0c0bb28 100644 --- a/SAVideoRangeSlider/SAVideoRangeSlider.m +++ b/SAVideoRangeSlider/SAVideoRangeSlider.m @@ -44,10 +44,11 @@ @implementation SAVideoRangeSlider #define SLIDER_BORDERS_SIZE 6.0f #define BG_VIEW_BORDERS_SIZE 3.0f +#define FRAME_IMAGEVIEW_CONTENT_MODE UIViewContentModeScaleAspectFill +const int FRAME_PIC_WIDTH = 20; - (id)initWithFrame:(CGRect)frame videoUrl:(NSURL *)videoUrl{ - self = [super initWithFrame:frame]; if (self) { @@ -56,6 +57,7 @@ - (id)initWithFrame:(CGRect)frame videoUrl:(NSURL *)videoUrl{ int thumbWidth = ceil(frame.size.width*0.05); _bgView = [[UIControl alloc] initWithFrame:CGRectMake(thumbWidth-BG_VIEW_BORDERS_SIZE, 0, frame.size.width-(thumbWidth*2)+BG_VIEW_BORDERS_SIZE*2, frame.size.height)]; + [_bgView.layer setMasksToBounds:YES]; _bgView.layer.borderColor = [UIColor grayColor].CGColor; _bgView.layer.borderWidth = BG_VIEW_BORDERS_SIZE; [self addSubview:_bgView]; @@ -330,14 +332,12 @@ -(void)getMovieFrame{ AVAsset *myAsset = [[AVURLAsset alloc] initWithURL:_videoUrl options:nil]; self.imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:myAsset]; + self.imageGenerator.appliesPreferredTrackTransform = YES; - if ([self isRetina]){ - self.imageGenerator.maximumSize = CGSizeMake(_bgView.frame.size.width*2, _bgView.frame.size.height*2); - } else { - self.imageGenerator.maximumSize = CGSizeMake(_bgView.frame.size.width, _bgView.frame.size.height); - } + CGFloat scale = [[UIScreen mainScreen] scale]; + self.imageGenerator.maximumSize = CGSizeMake(_bgView.frame.size.width*scale, _bgView.frame.size.height*scale); - int picWidth = 20; + int picWidth = FRAME_PIC_WIDTH; // First image NSError *error; @@ -351,11 +351,10 @@ -(void)getMovieFrame{ videoScreen = [[UIImage alloc] initWithCGImage:halfWayImage]; } UIImageView *tmp = [[UIImageView alloc] initWithImage:videoScreen]; - CGRect rect=tmp.frame; - rect.size.width=picWidth; - tmp.frame=rect; + tmp.contentMode = FRAME_IMAGEVIEW_CONTENT_MODE; + [tmp.layer setMasksToBounds:YES]; + [_bgView addSubview:tmp]; - picWidth = tmp.frame.size.width; CGImageRelease(halfWayImage); } @@ -381,35 +380,18 @@ -(void)getMovieFrame{ CGImageRef halfWayImage = [self.imageGenerator copyCGImageAtTime:timeFrame actualTime:&actualTime error:&error]; - UIImage *videoScreen; - if ([self isRetina]){ - videoScreen = [[UIImage alloc] initWithCGImage:halfWayImage scale:2.0 orientation:UIImageOrientationUp]; - } else { - videoScreen = [[UIImage alloc] initWithCGImage:halfWayImage]; - } - + UIImage *videoScreen = [[UIImage alloc] initWithCGImage:halfWayImage scale:[[UIScreen mainScreen] scale] orientation:UIImageOrientationUp]; UIImageView *tmp = [[UIImageView alloc] initWithImage:videoScreen]; - + tmp.contentMode = FRAME_IMAGEVIEW_CONTENT_MODE; + [tmp.layer setMasksToBounds:YES]; CGRect currentFrame = tmp.frame; currentFrame.origin.x = ii*picWidth; - - currentFrame.size.width=picWidth; prefreWidth+=currentFrame.size.width; - - if( i == picsCnt-1){ - currentFrame.size.width-=6; - } tmp.frame = currentFrame; - int all = (ii+1)*tmp.frame.size.width; - - if (all > _bgView.frame.size.width){ - int delta = all - _bgView.frame.size.width; - currentFrame.size.width -= delta; - } ii++; @@ -456,6 +438,8 @@ -(void)getMovieFrame{ UIImageView *tmp = [[UIImageView alloc] initWithImage:videoScreen]; + tmp.contentMode = FRAME_IMAGEVIEW_CONTENT_MODE; + [tmp.layer setMasksToBounds:YES]; int all = (i+1)*tmp.frame.size.width; diff --git a/SAVideoRangeSliderExample/SAVideoRangeSliderExample.xcodeproj/project.pbxproj b/SAVideoRangeSliderExample/SAVideoRangeSliderExample.xcodeproj/project.pbxproj index cabb584..be66551 100644 --- a/SAVideoRangeSliderExample/SAVideoRangeSliderExample.xcodeproj/project.pbxproj +++ b/SAVideoRangeSliderExample/SAVideoRangeSliderExample.xcodeproj/project.pbxproj @@ -28,7 +28,6 @@ 842D00DA16F7A68100BC2959 /* SASliderLeft.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D00D416F7A68100BC2959 /* SASliderLeft.m */; }; 842D00DB16F7A68100BC2959 /* SASliderRight.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D00D616F7A68100BC2959 /* SASliderRight.m */; }; 842D00DC16F7A68100BC2959 /* SAVideoRangeSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D00D816F7A68100BC2959 /* SAVideoRangeSlider.m */; }; - 9EDFED28191D1FAA00528292 /* VideoRangeSlider.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 9EDFED27191D1FAA00528292 /* VideoRangeSlider.podspec */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -218,7 +217,6 @@ 842D009E16F7064700BC2959 /* Default-568h@2x.png in Resources */, 842D00A416F7064700BC2959 /* ViewController_iPhone.xib in Resources */, 842D00A716F7064700BC2959 /* ViewController_iPad.xib in Resources */, - 9EDFED28191D1FAA00528292 /* VideoRangeSlider.podspec in Resources */, 842D00C116F70AF500BC2959 /* thaiPhuketKaronBeach.MOV in Resources */, ); runOnlyForDeploymentPostprocessing = 0;