This commit is contained in:
2014-08-15 20:37:32 +08:00
parent d106aea2a7
commit 60f95475e4
8 changed files with 1 additions and 427 deletions
-20
View File
@@ -29,8 +29,6 @@
A94FE520199C9C6800626DE5 /* MoveSocialCellView.xib in Resources */ = {isa = PBXBuildFile; fileRef = A94FE51F199C9C6800626DE5 /* MoveSocialCellView.xib */; };
A96F2A7C199D008200608237 /* UIButton+Bootstrap.m in Sources */ = {isa = PBXBuildFile; fileRef = A96F2A7B199D008200608237 /* UIButton+Bootstrap.m */; };
A96F2A7F199D01C000608237 /* NSString+FontAwesome.m in Sources */ = {isa = PBXBuildFile; fileRef = A96F2A7E199D01C000608237 /* NSString+FontAwesome.m */; };
A96F2A85199D1D6800608237 /* HdPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = A96F2A82199D1D6800608237 /* HdPageControl.m */; };
A96F2A86199D1D6800608237 /* HDScrollview.m in Sources */ = {isa = PBXBuildFile; fileRef = A96F2A84199D1D6800608237 /* HDScrollview.m */; };
A988A8FC199A50D900EB10AA /* TriangleView.m in Sources */ = {isa = PBXBuildFile; fileRef = A988A8FB199A50D900EB10AA /* TriangleView.m */; };
A988A900199A751500EB10AA /* FundListCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A988A8FF199A751500EB10AA /* FundListCell.m */; };
A988A902199A755300EB10AA /* FundListCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = A988A901199A755300EB10AA /* FundListCell.xib */; };
@@ -168,10 +166,6 @@
A96F2A7B199D008200608237 /* UIButton+Bootstrap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+Bootstrap.m"; sourceTree = "<group>"; };
A96F2A7D199D01C000608237 /* NSString+FontAwesome.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+FontAwesome.h"; sourceTree = "<group>"; };
A96F2A7E199D01C000608237 /* NSString+FontAwesome.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+FontAwesome.m"; sourceTree = "<group>"; };
A96F2A81199D1D6800608237 /* HdPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HdPageControl.h; sourceTree = "<group>"; };
A96F2A82199D1D6800608237 /* HdPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HdPageControl.m; sourceTree = "<group>"; };
A96F2A83199D1D6800608237 /* HDScrollview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HDScrollview.h; sourceTree = "<group>"; };
A96F2A84199D1D6800608237 /* HDScrollview.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HDScrollview.m; sourceTree = "<group>"; };
A988A8FA199A50D900EB10AA /* TriangleView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TriangleView.h; sourceTree = "<group>"; };
A988A8FB199A50D900EB10AA /* TriangleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TriangleView.m; sourceTree = "<group>"; };
A988A8FE199A751500EB10AA /* FundListCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FundListCell.h; sourceTree = "<group>"; };
@@ -375,17 +369,6 @@
path = UIButtonUtil;
sourceTree = "<group>";
};
A96F2A80199D1D6800608237 /* HDScrollView */ = {
isa = PBXGroup;
children = (
A96F2A81199D1D6800608237 /* HdPageControl.h */,
A96F2A82199D1D6800608237 /* HdPageControl.m */,
A96F2A83199D1D6800608237 /* HDScrollview.h */,
A96F2A84199D1D6800608237 /* HDScrollview.m */,
);
path = HDScrollView;
sourceTree = "<group>";
};
A988A8F9199A50B600EB10AA /* UIViewShape */ = {
isa = PBXGroup;
children = (
@@ -535,7 +518,6 @@
A9AF6C4A19949B510076C0EE /* Common */ = {
isa = PBXGroup;
children = (
A96F2A80199D1D6800608237 /* HDScrollView */,
A96F2A79199D007700608237 /* UIButtonUtil */,
A988A8F9199A50B600EB10AA /* UIViewShape */,
A93F87C71999E4DA00875287 /* AttributedString */,
@@ -855,8 +837,6 @@
files = (
A93F8801199A077F00875287 /* ListViewController.m in Sources */,
A988A8FC199A50D900EB10AA /* TriangleView.m in Sources */,
A96F2A85199D1D6800608237 /* HdPageControl.m in Sources */,
A96F2A86199D1D6800608237 /* HDScrollview.m in Sources */,
A9EAA05619988C55001A872A /* MRCircularProgressView.m in Sources */,
A9AF6C961994C5700076C0EE /* UIView+Extension.m in Sources */,
A9AF6C921994C5700076C0EE /* MJRefreshFooterView.m in Sources */,
@@ -1,39 +0,0 @@
//
// HdScrollView.h
// ScrollView
//
// Created by Hu Di on 13-10-11.
// Copyright (c) 2013年 Sanji. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "HdPageControl.h"
@protocol HDScrollviewDelegate <NSObject>
-(void)TapView:(int)index;
@end
@interface HDScrollview : UIScrollView<UIScrollViewDelegate>
@property (nonatomic, strong) NSTimer *autoScrollTimer;
@property (nonatomic,strong) HdPageControl *pagecontrol;
@property (nonatomic,assign) NSInteger currentPageIndex;
@property (assign,nonatomic) id<HDScrollviewDelegate> HDdelegate;
@property (nonatomic, assign) BOOL autoScroll; // default is YES, set NO to turn off autoScroll
@property (nonatomic, assign) NSUInteger scrollInterval;
/**
* @brief 不循环
*/
-(id)initWithFrame:(CGRect)frame withImageView:(NSMutableArray *)imageview;
/**
* @brief 循环滚动
*/
-(id)initLoopScrollWithFrame:(CGRect)frame withImageView:(NSMutableArray *)imageview;
-(void)HDscrollViewDidScroll;
-(void)HDscrollViewDidEndDecelerating;
@end
@interface UIImageView (CopyImageview)<NSCoding>
@end
@@ -1,248 +0,0 @@
//
// HdScrollView.m
// ScrollView
//
// Created by Hu Di on 13-10-11.
// Copyright (c) 2013年 Sanji. All rights reserved.
//
#import "HDScrollview.h"
@interface HDScrollview()
{
BOOL loop;
NSMutableArray *imageArray;
}
@end
@implementation HDScrollview
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;
self.scrollsToTop = NO;
self.pagingEnabled=YES;
self.bounces=NO;
self.userInteractionEnabled=YES;
[self setContentOffset:CGPointMake(0, 0)];
[self setContentOffset:CGPointMake(self.frame.size.width, 0)];
UITapGestureRecognizer *Recognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
Recognizer.numberOfTapsRequired=1;
[self addGestureRecognizer:Recognizer];
if (!self.pagecontrol) {
self.pagecontrol=[[HdPageControl alloc]init];
self.pagecontrol.currentPage=0;//当前页数
self.pagecontrol.userInteractionEnabled = YES;
[self.pagecontrol addTarget:self action:@selector(pageTurn:) forControlEvents:UIControlEventTouchUpInside];
}
}
return self;
}
-(id)initWithFrame:(CGRect)frame withImageView:(NSMutableArray *)imageviewarr
{
self = [self initWithFrame:frame];
if (self)
{
}
imageArray=[[NSMutableArray alloc] initWithArray:imageviewarr];
loop=NO;
NSUInteger pageCount=[imageviewarr count];
[self setContentSize:CGSizeMake(self.frame.size.width*pageCount, self.frame.size.height)];
CGRect bounds=self.frame;
for (int i=0; i<pageCount; i++) {
bounds.origin.x=bounds.size.width*i;
UIImageView *imageview=[imageviewarr objectAtIndex:i];
imageview.userInteractionEnabled=YES;
imageview.frame=bounds;
[self addSubview:imageview];
}
self.pagecontrol.numberOfPages=pageCount;//总的图片页数
[self.pagecontrol addObserver:self forKeyPath:@"currentPage" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:NULL];
return self;
}
-(id)initLoopScrollWithFrame:(CGRect)frame withImageView:(NSMutableArray *)ArrImageView
{
self = [self initWithFrame:frame];
if (self)
{
}
loop=YES;
imageArray=ArrImageView;
NSMutableArray *tempArray=[NSMutableArray arrayWithArray:ArrImageView];
//深拷贝imageview上的控件
UIImageView *imageview1=[ArrImageView objectAtIndex:([ArrImageView count]-1)];
UIImageView *imageview2=[ArrImageView objectAtIndex:0];
NSData *data1=[NSKeyedArchiver archivedDataWithRootObject:imageview1];
NSData *data2=[NSKeyedArchiver archivedDataWithRootObject:imageview2];
UIImageView *imageview3=[NSKeyedUnarchiver unarchiveObjectWithData:data1];
UIImageView *imageview4=[NSKeyedUnarchiver unarchiveObjectWithData:data2];
[tempArray insertObject:imageview3 atIndex:0];
[tempArray addObject:imageview4];
NSUInteger pageCount=[tempArray count];
[self setContentSize:CGSizeMake(self.frame.size.width*pageCount, self.frame.size.height)];
CGRect bounds=self.frame;
for (int i=0; i<pageCount; i++) {
bounds.origin.x=bounds.size.width*i;
UIImageView *imageview=[tempArray objectAtIndex:i];
imageview.userInteractionEnabled=YES;
imageview.frame=bounds;
imageview.contentMode = UIViewContentModeScaleToFill;
imageview.clipsToBounds = YES;
[self addSubview:imageview];
}
self.pagecontrol.numberOfPages=pageCount-2;//总的图片页数
[self.pagecontrol addObserver:self forKeyPath:@"currentPage" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:NULL];
self.currentPageIndex = 1;
return self;
}
- (void)setScrollInterval:(NSUInteger)scrollInterval
{
_scrollInterval = scrollInterval;
if (self.autoScrollTimer && self.autoScrollTimer.isValid) {
[self.autoScrollTimer invalidate];
self.autoScrollTimer = nil;
}
// self.autoScrollTimer = [NSTimer scheduledTimerWithTimeInterval:self.scrollInterval target:self selector:@selector(handleScrollTimer:) userInfo:nil repeats:YES];
}
- (void)handleScrollTimer:(NSTimer *)timer
{
if (self.pagecontrol.numberOfPages == 0) {
return;
}
self.currentPageIndex++;
[self autoTurn];
}
-(void)pageTurn:(UIPageControl *)sender
{
CGSize viewSize = self.frame.size;
CGRect rect;
if (loop) {
rect = CGRectMake((sender.currentPage+1) * viewSize.width, 0, viewSize.width, viewSize.height);
}
else
{
rect = CGRectMake(sender.currentPage * viewSize.width, 0, viewSize.width, viewSize.height);
}
[self scrollRectToVisible:rect animated:YES];
}
-(void)autoTurn
{
CGSize viewSize = self.frame.size;
CGRect rect = CGRectMake(self.currentPageIndex * viewSize.width, 0, viewSize.width, viewSize.height);
[self scrollRectToVisible:rect animated:YES];
[self HDscrollViewDidScroll];
[self HDscrollViewDidEndDecelerating];
}
-(void)HDscrollViewDidScroll
{
if (self.contentOffset.y > 0) {
[self setContentOffset:CGPointMake(self.contentOffset.x, 0)];
return;
}
if (loop) {
CGFloat pageWidth = self.frame.size.width;
int page = floor((self.contentOffset.x - pageWidth / 2) / pageWidth)+1;
self.currentPageIndex=page;
if (self.currentPageIndex == 5) {
page = 1;
}
self.pagecontrol.currentPage=(page-1);
}
}
-(void)HDscrollViewDidEndDecelerating
{
if (self.autoScrollTimer && self.autoScrollTimer.isValid) {
[self.autoScrollTimer invalidate];
}
self.autoScrollTimer = [NSTimer scheduledTimerWithTimeInterval:self.scrollInterval target:self selector:@selector(handleScrollTimer:) userInfo:nil repeats:YES];
if (loop) {
if (0==self.currentPageIndex) {
[self setContentOffset:CGPointMake([imageArray count]*self.bounds.size.width, 0)];
}
if (([imageArray count]+1)==self.currentPageIndex) {
[self setContentOffset:CGPointMake(self.bounds.size.width, 0)];
[self HDscrollViewDidScroll];
}
}
else
{
//更新UIPageControl的当前页
CGPoint offset = self.contentOffset;
CGRect bounds = self.frame;
[self.pagecontrol setCurrentPage:offset.x / bounds.size.width];
}
}
-(void)tap
{
[self.HDdelegate TapView:self.pagecontrol.currentPage];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"currentPage"]) {
[self pageTurn:self.pagecontrol];
[self.pagecontrol removeObserver:self forKeyPath:@"currentPage"];
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
@implementation UIImageView (CopyImageview)
-(void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.backgroundColor forKey:@"backgroundColor"];
[aCoder encodeObject:self.image forKey:@"image"];
[aCoder encodeInt:self.contentMode forKey:@"contentMode"];
[aCoder encodeInt:self.subviews.count forKey:@"subviewscount"];
for(int i=0;i<self.subviews.count;i++)
{
UIView *view=self.subviews[i];
[aCoder encodeObject:view forKey:[NSString stringWithFormat:@"view%d",i]];
}
}
-(id)initWithCoder:(NSCoder *)aDecoder
{
if (self=[super init]) {
self.backgroundColor=[aDecoder decodeObjectForKey:@"backgroundColor"];
self.image=[aDecoder decodeObjectForKey:@"image"];
self.contentMode=[aDecoder decodeIntForKey:@"contentMode"];
int subviewscount=[aDecoder decodeIntForKey:@"subviewscount"];
for(int i=0;i<subviewscount;i++)
{
UIView* view=[aDecoder decodeObjectForKey:[NSString stringWithFormat:@"view%d",i]];
[self addSubview:view];
}
}
return self;
}
@end
@@ -1,14 +0,0 @@
//
// HdPageControl.h
// ScrollView
//
// Created by Hu Di on 13-11-20.
// Copyright (c) 2013年 Sanji. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface HdPageControl : UIPageControl
@property (strong,nonatomic)UIColor *currentcolor;
@property (strong,nonatomic)UIColor *othercolor;
@end
@@ -1,80 +0,0 @@
//
// HdPageControl.m
// ScrollView
//
// Created by Hu Di on 13-11-20.
// Copyright (c) 2013年 Sanji. All rights reserved.
//
#import "HdPageControl.h"
#define IOS7 [[UIDevice currentDevice].systemVersion doubleValue]>=7.0
@implementation HdPageControl
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void) updateDots
{
for (int i = 0; i < [self.subviews count]; i++)
{
UIView* pageIcon = [self.subviews objectAtIndex:i];
pageIcon.layer.cornerRadius=3;
pageIcon.layer.masksToBounds=YES;
//NSLog(@"%@",NSStringFromClass([pageIcon class]));
if ([NSStringFromClass([pageIcon class]) isEqualToString:@"UIImageView"]) {
if (i == self.currentPage)
{
((UIImageView*)pageIcon).image=[self createImageWithColor:self.currentcolor];
}
else
{
((UIImageView*)pageIcon).image=[self createImageWithColor:self.othercolor];
}
}
else
{
if (i == self.currentPage)
{
pageIcon.backgroundColor=self.currentcolor;
}
else
{
pageIcon.backgroundColor=self.othercolor;
}
}
}
}
-(void) setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
- (UIImage *)createImageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
+1 -4
View File
@@ -7,11 +7,8 @@
//
#import <UIKit/UIKit.h>
#import "HDScrollview.h"
#import "ImagePlayerView.h"
@interface HomeAdView : UIView<HDScrollviewDelegate,UIScrollViewDelegate,ImagePlayerViewDelegate>
@interface HomeAdView : UIView<UIScrollViewDelegate,ImagePlayerViewDelegate>
{
HDScrollview* _scrollview;
}
@property(strong, nonatomic)HDScrollview* scrollview;
@end
@@ -7,7 +7,6 @@
//
#import "HomeAdView.h"
#import "HDScrollview.h"
@implementation HomeAdView
{
NSArray *imageArray;
@@ -55,27 +54,6 @@
}
*/
#pragma mark ==========UIScrollViewDelegate============
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// disable v direction scroll
[_scrollview HDscrollViewDidScroll];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)_scrollView
{
[_scrollview HDscrollViewDidEndDecelerating];
}
-(void)TapView:(int)index
{
DLog(@"点击了第%d个页面",index);
//下面可以根据自己的需求操作
//Example
}
#pragma mark ImagePlayerDelegate
- (void)imagePlayerView:(ImagePlayerView *)imagePlayerView loadImageForImageView:(UIImageView *)imageView index:(NSInteger)index
{