diff --git a/AdView/AdView.xcodeproj/project.xcworkspace/xcuserdata/heguoping.xcuserdatad/UserInterfaceState.xcuserstate b/AdView/AdView.xcodeproj/project.xcworkspace/xcuserdata/heguoping.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..c312c1c
Binary files /dev/null and b/AdView/AdView.xcodeproj/project.xcworkspace/xcuserdata/heguoping.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/AdView/AdView.xcodeproj/xcuserdata/heguoping.xcuserdatad/xcschemes/AdView.xcscheme b/AdView/AdView.xcodeproj/xcuserdata/heguoping.xcuserdatad/xcschemes/AdView.xcscheme
new file mode 100644
index 0000000..5da0db6
--- /dev/null
+++ b/AdView/AdView.xcodeproj/xcuserdata/heguoping.xcuserdatad/xcschemes/AdView.xcscheme
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/AdView/AdView.xcodeproj/xcuserdata/heguoping.xcuserdatad/xcschemes/xcschememanagement.plist b/AdView/AdView.xcodeproj/xcuserdata/heguoping.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..a86c9c1
--- /dev/null
+++ b/AdView/AdView.xcodeproj/xcuserdata/heguoping.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,27 @@
+
+
+
+
+ SchemeUserState
+
+ AdView.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 53E54CF91AED3CF10077D764
+
+ primary
+
+
+ 53E54D121AED3CF10077D764
+
+ primary
+
+
+
+
+
diff --git a/AdView/AdView/AdView/AdView.h b/AdView/AdView/AdView/AdView.h
index a483613..128e7d1 100755
--- a/AdView/AdView/AdView/AdView.h
+++ b/AdView/AdView/AdView/AdView.h
@@ -33,6 +33,19 @@ typedef NS_ENUM(NSUInteger, AdTitleShowStyle)
AdTitleShowStyleRight,
};
+typedef NS_ENUM(NSUInteger, AdPictureShowStyle)
+{
+ /**
+ * @author ZY, 15-04-26
+ *
+ * 图片显示方式
+ */
+ AdPictureShowModeScaleToFill,
+ AdPictureShowModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
+ AdPictureShowModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped.
+ AdPictureShowModeCenter,
+};
+
@interface AdView : UIView
{
UILabel * _centerAdLabel;
@@ -52,13 +65,24 @@ typedef NS_ENUM(NSUInteger, AdTitleShowStyle)
* 设置page显示位置
*/
@property (assign,nonatomic) UIPageControlShowStyle PageControlShowStyle;
+/**
+ * @author ZY, 15-05-17
+ *
+ * pageControl显示偏移量
+ */
+@property (assign,nonatomic) UIEdgeInsets pageControlEdgeInsets;
/**
* @author ZY, 15-05-17
*
* 设置标题对应的位置
*/
@property (assign,nonatomic,readonly) AdTitleShowStyle adTitleStyle;
-
+/**
+ * @author ZY, 15-05-17
+ *
+ * 图片显示方式
+ */
+@property (assign,nonatomic) AdPictureShowStyle pictureShowStyle;
/**
* @author ZY, 15-05-17
*
@@ -148,4 +172,16 @@ typedef NS_ENUM(NSUInteger, AdTitleShowStyle)
* @param imageName 属性名称
*/
+ (id)adScrollViewWithFrame:(CGRect)frame modelArr:(NSArray *)modelArr imagePropertyName:(NSString *)imageName pageControlShowStyle:(UIPageControlShowStyle)PageControlShowStyle;
+/**
+ * 重新设置图片链接数组,刷新显示图片
+ *
+ * @param URLarr 新的URL数组
+ */
+- (void)reloadImageURLArray:(NSArray*)URLarr;
+/**
+ * 停止/开始自动滚屏
+ *
+ * @param URLarr 新的URL数组
+ */
+- (void)stopAutoScroll:(BOOL)stopOrNo;
@end
diff --git a/AdView/AdView/AdView/AdView.m b/AdView/AdView/AdView/AdView.m
index bd78000..8534318 100755
--- a/AdView/AdView/AdView/AdView.m
+++ b/AdView/AdView/AdView/AdView.m
@@ -101,14 +101,18 @@ - (void)willMoveToSuperview:(UIView *)newSuperview
[self setUpTime];
}
}
-
+//避免在父视图重载时,重复调用willMoveToSuperview,重定义定时器事件,造成定时器不断累加,滚动加快
- (void)setUpTime
{
- if (_isNeedCycleRoll&&_imageLinkURL.count>=2)
+ if (_isNeedCycleRoll && _imageLinkURL.count>=2 && !moveTimer)
{
moveTimer = [NSTimer scheduledTimerWithTimeInterval:_adMoveTime target:self selector:@selector(animalMoveImage:) userInfo:nil repeats:YES];
_isTimeUp = NO;
}
+ else if(_isNeedCycleRoll && _imageLinkURL.count>=2 && moveTimer)
+ {
+ [self stopAutoScroll:NO];
+ }
}
- (void)setIsNeedCycleRoll:(BOOL)isNeedCycleRoll
@@ -143,8 +147,13 @@ + (id)adScrollViewWithFrame:(CGRect)frame imageLinkURL:(NSArray *)imageLinkURL p
NSMutableArray * imagePaths = [[NSMutableArray alloc]init];
for (NSString * imageName in imageLinkURL)
{
- NSURL * imageURL = [NSURL URLWithString:imageName];
- [imagePaths addObject:imageURL];
+ //支持字符串数组和NSURL数组
+ if ([imageName isKindOfClass:[NSString class]]) {
+ NSURL * imageURL = [NSURL URLWithString:imageName];
+ [imagePaths addObject:imageURL];
+ }else if ([imageName isKindOfClass:[NSURL class]]){
+ [imagePaths addObject:imageName];
+ }
}
AdView * adView = [AdView adScrollViewWithFrame:frame imageLinkURL:imageLinkURL pageControlShowStyle:PageControlShowStyle];
adView.placeHoldImage = [UIImage imageNamed:imageName];
@@ -216,7 +225,10 @@ - (void)setImageLinkURL:(NSArray *)imageLinkURL
[self setPageControlShowStyle:self.PageControlShowStyle];
}
-
+#pragma mark - 重新设置图片链接数组,刷新显示图片(适用于上下拉刷新后,重新设置图片数组,更新图片)
+- (void)reloadImageURLArray:(NSArray*)URLarr{
+ [self setImageLinkURL:URLarr];
+}
#pragma mark - 设置每个对应广告对应的广告语
- (void)setAdTitleArray:(NSArray *)adTitleArray withShowStyle:(AdTitleShowStyle)adTitleStyle
@@ -302,7 +314,42 @@ - (void)setPageControlShowStyle:(UIPageControlShowStyle)PageControlShowStyle
_pageControl.enabled = NO;
[self addSubview:_pageControl];
}
-
+#pragma mark - 设置pageControl偏移量
+- (void)setPageControlEdgeInsets:(UIEdgeInsets)pageControlEdgeInsets{
+ CGRect orgiFrame = _pageControl.frame;
+ orgiFrame.origin.x += pageControlEdgeInsets.left;
+ orgiFrame.origin.x -= pageControlEdgeInsets.right;
+ orgiFrame.origin.y += pageControlEdgeInsets.top;
+ orgiFrame.origin.y -= pageControlEdgeInsets.bottom;
+ _pageControl.frame = orgiFrame;
+}
+#pragma mark - 设置图片展示缩放方式
+- (void)setPictureShowStyle:(AdPictureShowStyle)pictureShowStyle{
+ switch (pictureShowStyle) {
+ case AdPictureShowModeScaleToFill:
+ _leftImageView.contentMode = UIViewContentModeScaleToFill;
+ _centerImageView.contentMode = UIViewContentModeScaleToFill;
+ _rightImageView.contentMode = UIViewContentModeScaleToFill;
+ break;
+ case AdPictureShowModeScaleAspectFit:
+ _leftImageView.contentMode = UIViewContentModeScaleAspectFit;
+ _centerImageView.contentMode = UIViewContentModeScaleAspectFit;
+ _rightImageView.contentMode = UIViewContentModeScaleAspectFit;
+ break;
+ case AdPictureShowModeScaleAspectFill:
+ _leftImageView.contentMode = UIViewContentModeScaleAspectFill;
+ _centerImageView.contentMode = UIViewContentModeScaleAspectFill;
+ _rightImageView.contentMode = UIViewContentModeScaleAspectFill;
+ break;
+ case AdPictureShowModeCenter:
+ _leftImageView.contentMode = UIViewContentModeCenter;
+ _centerImageView.contentMode = UIViewContentModeCenter;
+ _rightImageView.contentMode = UIViewContentModeCenter;
+ break;
+ default:
+ break;
+ }
+}
#pragma mark - 计时器到时,系统滚动图片
- (void)animalMoveImage:(NSTimer *)time
{
@@ -310,7 +357,14 @@ - (void)animalMoveImage:(NSTimer *)time
_isTimeUp = YES;
[NSTimer scheduledTimerWithTimeInterval:0.4f target:self selector:@selector(scrollViewDidEndDecelerating:) userInfo:nil repeats:NO];
}
-
+#pragma mark 停止/开始自动滚屏
+- (void)stopAutoScroll:(BOOL)stopOrNo{
+ if (!stopOrNo){
+ [moveTimer setFireDate:[NSDate distantPast]];
+ }else{
+ [moveTimer setFireDate:[NSDate distantFuture]];
+ }
+}
#pragma mark - 图片停止时,调用该函数使得滚动视图复用
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
@@ -405,4 +459,4 @@ -(void)tap
_callBackForModel(self.models[centerImageIndex]);
}
}
-@end
\ No newline at end of file
+@end