Skip to content
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
9 changes: 9 additions & 0 deletions CustomScrollViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -60,6 +61,8 @@
C367A4971DE3E7EB0046E17E /* mom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = mom.png; sourceTree = "<group>"; };
C367A4991DE3E7F30046E17E /* haqi.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = haqi.png; sourceTree = "<group>"; };
C367A49B1DE3E7F90046E17E /* dun.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = dun.png; sourceTree = "<group>"; };
C3F8F3201EB8639C0084145E /* WMSigleAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMSigleAlertView.h; sourceTree = "<group>"; };
C3F8F3211EB8639C0084145E /* WMSigleAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WMSigleAlertView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
);
Expand Down Expand Up @@ -523,6 +529,7 @@
C367A48B1DE3E6D80046E17E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C367A48C1DE3E6D80046E17E /* Build configuration list for PBXNativeTarget "CustomScrollViewDemoTests" */ = {
isa = XCConfigurationList;
Expand All @@ -531,6 +538,7 @@
C367A48E1DE3E6D80046E17E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C367A48F1DE3E6D80046E17E /* Build configuration list for PBXNativeTarget "CustomScrollViewDemoUITests" */ = {
isa = XCConfigurationList;
Expand All @@ -539,6 +547,7 @@
C367A4911DE3E6D80046E17E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Binary file not shown.
6 changes: 5 additions & 1 deletion CustomScrollViewDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 11 additions & 10 deletions CustomScrollViewDemo/WMShuffleFigure.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -164,18 +164,19 @@ - (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);

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)
Expand All @@ -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];
Expand All @@ -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];

Expand All @@ -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];
}
Expand Down
13 changes: 13 additions & 0 deletions CustomScrollViewDemo/WMSigleAlertView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// WMCartAlertView.h
// Wemart
//
// Created by 冯文秀 on 16/8/26.
// Copyright © 2016年 冯文秀. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface WMSigleAlertView : NSObject
- (void)showAlertViewTitle:(NSString *)title bgView:(UIView *)bgView;
@end
83 changes: 83 additions & 0 deletions CustomScrollViewDemo/WMSigleAlertView.m
Original file line number Diff line number Diff line change
@@ -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