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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "53E54CF91AED3CF10077D764"
BuildableName = "AdView.app"
BlueprintName = "AdView"
ReferencedContainer = "container:AdView.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "53E54D121AED3CF10077D764"
BuildableName = "AdViewTests.xctest"
BlueprintName = "AdViewTests"
ReferencedContainer = "container:AdView.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "53E54CF91AED3CF10077D764"
BuildableName = "AdView.app"
BlueprintName = "AdView"
ReferencedContainer = "container:AdView.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "53E54CF91AED3CF10077D764"
BuildableName = "AdView.app"
BlueprintName = "AdView"
ReferencedContainer = "container:AdView.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "53E54CF91AED3CF10077D764"
BuildableName = "AdView.app"
BlueprintName = "AdView"
ReferencedContainer = "container:AdView.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>AdView.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>53E54CF91AED3CF10077D764</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>53E54D121AED3CF10077D764</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
38 changes: 37 additions & 1 deletion AdView/AdView/AdView/AdView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIScrollViewDelegate>
{
UILabel * _centerAdLabel;
Expand All @@ -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
*
Expand Down Expand Up @@ -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
70 changes: 62 additions & 8 deletions AdView/AdView/AdView/AdView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -302,15 +314,57 @@ - (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
{
[_adScrollView setContentOffset:CGPointMake(kAdViewWidth * 2, 0) animated:YES];
_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
{
Expand Down Expand Up @@ -405,4 +459,4 @@ -(void)tap
_callBackForModel(self.models[centerImageIndex]);
}
}
@end
@end