diff --git a/CustomScrollViewDemo.xcodeproj/project.pbxproj b/CustomScrollViewDemo.xcodeproj/project.pbxproj index 15ad476..2b6ee9b 100755 --- a/CustomScrollViewDemo.xcodeproj/project.pbxproj +++ b/CustomScrollViewDemo.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ C367A4981DE3E7EB0046E17E /* mom.png in Resources */ = {isa = PBXBuildFile; fileRef = C367A4971DE3E7EB0046E17E /* mom.png */; }; C367A49A1DE3E7F30046E17E /* haqi.png in Resources */ = {isa = PBXBuildFile; fileRef = C367A4991DE3E7F30046E17E /* haqi.png */; }; C367A49C1DE3E7F90046E17E /* dun.png in Resources */ = {isa = PBXBuildFile; fileRef = C367A49B1DE3E7F90046E17E /* dun.png */; }; + C3F8F3221EB8639C0084145E /* WMSigleAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3F8F3211EB8639C0084145E /* WMSigleAlertView.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -60,6 +61,8 @@ C367A4971DE3E7EB0046E17E /* mom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = mom.png; sourceTree = ""; }; C367A4991DE3E7F30046E17E /* haqi.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = haqi.png; sourceTree = ""; }; C367A49B1DE3E7F90046E17E /* dun.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = dun.png; sourceTree = ""; }; + C3F8F3201EB8639C0084145E /* WMSigleAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMSigleAlertView.h; sourceTree = ""; }; + C3F8F3211EB8639C0084145E /* WMSigleAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WMSigleAlertView.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -116,6 +119,8 @@ C367A4661DE3E6D80046E17E /* ViewController.m */, C367A4921DE3E7000046E17E /* WMShuffleFigure.h */, C367A4931DE3E7000046E17E /* WMShuffleFigure.m */, + C3F8F3201EB8639C0084145E /* WMSigleAlertView.h */, + C3F8F3211EB8639C0084145E /* WMSigleAlertView.m */, C367A49B1DE3E7F90046E17E /* dun.png */, C367A4991DE3E7F30046E17E /* haqi.png */, C367A4681DE3E6D80046E17E /* Main.storyboard */, @@ -292,6 +297,7 @@ files = ( C367A4671DE3E6D80046E17E /* ViewController.m in Sources */, C367A4641DE3E6D80046E17E /* AppDelegate.m in Sources */, + C3F8F3221EB8639C0084145E /* WMSigleAlertView.m in Sources */, C367A4611DE3E6D70046E17E /* main.m in Sources */, C367A4941DE3E7000046E17E /* WMShuffleFigure.m in Sources */, ); @@ -523,6 +529,7 @@ C367A48B1DE3E6D80046E17E /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; C367A48C1DE3E6D80046E17E /* Build configuration list for PBXNativeTarget "CustomScrollViewDemoTests" */ = { isa = XCConfigurationList; @@ -531,6 +538,7 @@ C367A48E1DE3E6D80046E17E /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; C367A48F1DE3E6D80046E17E /* Build configuration list for PBXNativeTarget "CustomScrollViewDemoUITests" */ = { isa = XCConfigurationList; @@ -539,6 +547,7 @@ C367A4911DE3E6D80046E17E /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/CustomScrollViewDemo.xcodeproj/project.xcworkspace/xcuserdata/Hera.xcuserdatad/UserInterfaceState.xcuserstate b/CustomScrollViewDemo.xcodeproj/project.xcworkspace/xcuserdata/Hera.xcuserdatad/UserInterfaceState.xcuserstate index f694d56..2e2c637 100755 Binary files a/CustomScrollViewDemo.xcodeproj/project.xcworkspace/xcuserdata/Hera.xcuserdatad/UserInterfaceState.xcuserstate and b/CustomScrollViewDemo.xcodeproj/project.xcworkspace/xcuserdata/Hera.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/CustomScrollViewDemo/ViewController.m b/CustomScrollViewDemo/ViewController.m index 74babbb..41b4092 100755 --- a/CustomScrollViewDemo/ViewController.m +++ b/CustomScrollViewDemo/ViewController.m @@ -32,9 +32,13 @@ - (void)viewDidLoad { [self.view addSubview:shuffleView]; } + +# pragma mark ---- 滚动视图 的代理方法 ---- - (void)shuffleView:(WMShuffleFigure *)shuffleView clickImageAtIndex:(NSInteger)index { - + NSLog(@"滚动视图 图片数组 ---- %@", shuffleView.imageArray); + NSLog(@"图片数组 下表 ---- %ld", index); + } - (void)didReceiveMemoryWarning { diff --git a/CustomScrollViewDemo/WMShuffleFigure.m b/CustomScrollViewDemo/WMShuffleFigure.m index 1daf845..30c6233 100755 --- a/CustomScrollViewDemo/WMShuffleFigure.m +++ b/CustomScrollViewDemo/WMShuffleFigure.m @@ -110,7 +110,7 @@ - (void)setImageArray:(NSArray *)imageArray{ [_images addObject:imageArray[i]]; } } - //防止在滚动过程中重新给imageArray赋值时报错 + // 防止在滚动过程中重新给imageArray赋值时报错 if (_currIndex >= _images.count)_currIndex = _images.count - 1; self.currImageView.image = _images[_currIndex]; self.pageControl.numberOfPages = _images.count; @@ -124,7 +124,7 @@ - (void)setScrollViewContentSize { self.scrollView.contentOffset = CGPointMake(self.width * 2, 0); self.currImageView.frame = CGRectMake(self.width * 2, 0, self.width, self.height); if (_changeMode == ChangeModeFade) { - //淡入淡出模式,两个imageView都在同一位置,改变透明度就可以了 + // 淡入淡出模式,两个imageView都在同一位置,改变透明度就可以了 _currImageView.frame = CGRectMake(0, 0, self.width, self.height); _otherImageView.frame = self.currImageView.frame; _otherImageView.alpha = 0; @@ -135,7 +135,7 @@ - (void)setScrollViewContentSize { [self startTimer]; } else { - //只要一张图片时,scrollview不可滚动,且关闭定时器 + // 只要一张图片时,scrollview不可滚动,且关闭定时器 self.scrollView.contentSize = CGSizeZero; self.scrollView.contentOffset = CGPointZero; self.currImageView.frame = CGRectMake(0, 0, self.width, self.height); @@ -164,11 +164,11 @@ - (void)setPagePosition:(PageControlPosition)pagePosition { if (_pageControl.hidden) return; CGSize size; - if (!_pageImageSize.width) {//没有设置图片,系统原有样式 + if (!_pageImageSize.width) {// 没有设置图片,系统原有样式 size = [_pageControl sizeForNumberOfPages:_pageControl.numberOfPages]; size.height = 8; } - else {//设置图片了 + else {// 设置图片了 size = CGSizeMake(10 * (_pageControl.numberOfPages * 2 - 1), 10); } _pageControl.frame = CGRectMake(0, 0, size.width, size.height); @@ -176,6 +176,7 @@ - (void)setPagePosition:(PageControlPosition)pagePosition { CGFloat centerY = self.height - size.height * 0.5 - VERMARGIN; CGFloat pointY = self.height - size.height - VERMARGIN; + // 判断位置 调换 if (_pagePosition == PositionDefault || _pagePosition == PositionBottomCenter) _pageControl.center = CGPointMake(self.width * 0.5, centerY); else if (_pagePosition == PositionTopCenter) @@ -194,9 +195,9 @@ - (void)setTime:(NSTimeInterval)time { #pragma mark --- 定时器 --- - (void)startTimer { - //如果只有一张图片,则直接返回,不开启定时器 + // 如果只有一张图片,则直接返回,不开启定时器 if (_images.count <= 1) return; - //如果定时器已开启,先停止再重新开启 + // 如果定时器已开启,先停止再重新开启 if (self.timer) [self stopTimer]; self.timer = [NSTimer timerWithTimeInterval:_time < 2? DEFAULTTIME: _time target:self selector:@selector(nextPage) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; @@ -209,7 +210,7 @@ - (void)stopTimer { #pragma mark --- 开启定时器 --- - (void)nextPage { if (_changeMode == ChangeModeFade) { - //淡入淡出模式,不需要修改scrollview偏移量,改变两张图片的透明度即可 + // 淡入淡出模式,不需要修改scrollview偏移量,改变两张图片的透明度即可 self.nextIndex = (self.currIndex + 1) % _images.count; self.otherImageView.image = _images[_nextIndex]; @@ -229,10 +230,10 @@ - (void)nextPage { #pragma mark --- 布局子控件 --- - (void)layoutSubviews { [super layoutSubviews]; - //有导航控制器时,会默认在scrollview上方添加64的内边距,这里强制设置为0 + // 有导航控制器时,会默认在scrollview上方添加64的内边距,这里强制设置为0 _scrollView.contentInset = UIEdgeInsetsZero; _scrollView.frame = self.bounds; - //重新计算pageControl的位置 + // 重新计算pageControl的位置 self.pagePosition = self.pagePosition; [self setScrollViewContentSize]; } diff --git a/CustomScrollViewDemo/WMSigleAlertView.h b/CustomScrollViewDemo/WMSigleAlertView.h new file mode 100644 index 0000000..2a972c4 --- /dev/null +++ b/CustomScrollViewDemo/WMSigleAlertView.h @@ -0,0 +1,13 @@ +// +// WMCartAlertView.h +// Wemart +// +// Created by 冯文秀 on 16/8/26. +// Copyright © 2016年 冯文秀. All rights reserved. +// + +#import + +@interface WMSigleAlertView : NSObject +- (void)showAlertViewTitle:(NSString *)title bgView:(UIView *)bgView; +@end diff --git a/CustomScrollViewDemo/WMSigleAlertView.m b/CustomScrollViewDemo/WMSigleAlertView.m new file mode 100644 index 0000000..dccd118 --- /dev/null +++ b/CustomScrollViewDemo/WMSigleAlertView.m @@ -0,0 +1,83 @@ +// +// WMCartAlertView.m +// Wemart +// +// Created by 冯文秀 on 16/8/26. +// Copyright © 2016年 冯文秀. All rights reserved. +// + +#import "WMSigleAlertView.h" +#define WMLightFont(FontSize) [UIFont fontWithName:@"PingFangSC-Light" size:FontSize] +#define WMMediumFont(FontSize) [UIFont fontWithName:@"PingFangSC-Medium" size:FontSize] +#define ColorRGB(a,b,c,d) [UIColor colorWithRed:a/255.0 green:b/255.0 blue:c/255.0 alpha:d] + + +@interface WMSigleAlertView() +@property (nonatomic, strong) NSTimer *timer; +@property (nonatomic, strong) UILabel * titleLabel; + +@end + +@implementation WMSigleAlertView + +- (void)showAlertViewTitle:(NSString *)title bgView:(UIView *)bgView +{ + CGRect bounds = [title boundingRectWithSize:CGSizeMake(1000, 28) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:WMMediumFont(13.f) forKey:NSFontAttributeName] context:nil]; + self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, bounds.size.width + 30, 26)]; + self.titleLabel.center = bgView.center; + self.titleLabel.backgroundColor = ColorRGB(0, 0, 0, 0.8); + self.titleLabel.layer.cornerRadius = 5; + self.titleLabel.clipsToBounds = YES; + self.titleLabel.font = WMLightFont(14.f); + self.titleLabel.textColor = [UIColor whiteColor]; + self.titleLabel.text = title; + self.titleLabel.textAlignment = NSTextAlignmentCenter; + [bgView addSubview:_titleLabel]; + + [self shakeUpShow:_titleLabel]; + [self openTimeByRuntime]; +} + +#pragma mark --- 添加动画 --- +- (void)shakeUpShow:(UIView *)shakeView +{ + CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; + NSMutableArray *mutableArray = [NSMutableArray array]; + NSValue *value1 = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]; + NSValue *value2 = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]; + NSValue *value3 = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]; + NSValue *value4 = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]; + [mutableArray addObject:value1]; + [mutableArray addObject:value2]; + [mutableArray addObject:value3]; + [mutableArray addObject:value4]; + animation.duration = 0.5; + animation.values = [mutableArray copy]; + [shakeView.layer addAnimation:animation forKey:nil]; +} + +#pragma mark --- 开启计时器 --- +- (void)openTimeByRuntime +{ + self.timer = [NSTimer timerWithTimeInterval:1.2 target:self selector:@selector(dismissViewAction) userInfo:nil repeats:NO]; + if (self.timer != nil) { + [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode]; + } +} + +- (void)dismissViewAction +{ + if (_timer != nil) { + [self.timer invalidate]; + self.timer = nil; + } + [UIView beginAnimations:nil context:nil]; + [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; + [UIView setAnimationDuration:1.4]; + [UIView setAnimationDelegate:self]; + self.titleLabel.hidden = YES; + [self.titleLabel removeFromSuperview]; + [UIView commitAnimations]; +} + +@end