【IOS】实现一种书本的展示特效

阅读更多

【原创作品, 欢迎转载,转载请在明显处注明! 谢谢。

原文地址:http://blog.csdn.net/toss156/article/details/7630518


最近在做一个电子书的项目,其中有一个书架的功能。看了很多其他应用的书架,有些实现的效果真的很不错,就比如《宝宝爱看书》,于是也仿着自己写了一个,虽然最后没能用在项目中,但是还是觉得很不错,在这里和大家分享一下怎么实现的。

【IOS】实现一种书本的展示特效_第1张图片 一开始以列表的方式显示【IOS】实现一种书本的展示特效_第2张图片向上或者向下滑动,切换布局方式,位置的信息记录在plist中【IOS】实现一种书本的展示特效_第3张图片点击其中任意一本书,选中的书本移动到最前面,只有在最前面的书本是可以直接打开的。


// // UIBook.h // BookShelf // // Created by zhouhaifeng on 12-6-1. // Copyright (c) 2012年 zhouhaifeng. All rights reserved. // #import @interface UIBook : UIButton { id bookdelegate; int downPrecent; UILabel *precent; } @property (nonatomic) UILabel *precent; @property (nonatomic) id bookdelegate; -(void) setDownloadPrecent:(int) value; -(void) OnButtonClicked:(id)sender; @end @protocol UIBookDelegate @optional - (void)UIBook:(UIBook *)book clickedButtonAtIndex:(NSInteger)buttonIndex; @end
// // UIBook.m // BookShelf // // Created by zhouhaifeng on 12-6-1. // Copyright (c) 2012年 zhouhaifeng. All rights reserved. // #import "UIBook.h" @implementation UIBook @synthesize precent,bookdelegate; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { downPrecent = 100; // Initialization code [self setImage:[UIImage imageNamed:@"bookcover_temp.jpg"] forState:UIControlStateNormal]; UIImageView* progressbg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"loading_bg.png"]]; [progressbg setFrame:CGRectMake(100, 200, 96, 96)]; [self addSubview:progressbg]; UIImageView* loading_ring = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"loading_ring.png"]]; [loading_ring setFrame:CGRectMake(0, 0, 96, 96)]; [progressbg addSubview:loading_ring]; [UIView animateWithDuration:2.0f delay:0.0f options:UIViewAnimationOptionRepeat|UIViewAnimationCurveLinear animations:^{ loading_ring.transform = CGAffineTransformMakeRotation(M_PI); } completion:nil]; precent = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 96, 96)]; [precent setText:[NSString stringWithFormat:@"%d%%",downPrecent]]; [precent setTextColor:[UIColor whiteColor]]; [precent setBackgroundColor:[UIColor clearColor]]; [precent setTextAlignment:UITextAlignmentCenter]; [progressbg addSubview:precent]; [self addTarget:self action:@selector(OnButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; } return self; } -(void) OnButtonClicked:(id)sender { if (bookdelegate) { if ([bookdelegate respondsToSelector:@selector(UIBook:clickedButtonAtIndex:)]) { [bookdelegate UIBook:self clickedButtonAtIndex:self.tag]; } }else { NSLog(@"these is no delegate"); } } -(void) setDownloadPrecent:(int) value { downPrecent = value; [precent setText:[NSString stringWithFormat:@"%d%%",downPrecent]]; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end
// // ViewController.h // BookShelf // // Created by zhouhaifeng on 12-6-1. // Copyright (c) 2012年 zhouhaifeng. All rights reserved. // #import #import #import "UIBook.h" typedef enum { LayoutStateLine = 0, LayoutStateRandom }LayoutState; @interface ViewController : UIViewController { NSMutableArray *bookArray; LayoutState layoutState; } -(void) swapBooks:(NSInteger) bookA TwoBooks:(NSInteger) bookB; @property (nonatomic) NSMutableArray *bookArray; @end
// // ViewController.m // BookShelf // // Created by zhouhaifeng on 12-6-1. // Copyright (c) 2012年 zhouhaifeng. All rights reserved. // #define NUMBER 8 #import "ViewController.h" @interface ViewController () -(void) didSwipe:(UISwipeGestureRecognizer *) recognizer; -(void) layoutBooks; @end @implementation ViewController @synthesize bookArray; - (void)viewDidLoad { [super viewDidLoad]; [self.view setUserInteractionEnabled:YES]; bookArray = [NSMutableArray arrayWithCapacity:10]; layoutState = LayoutStateLine; //添加书本 for (int i = 0; i Demo的下载地址:http://download.csdn.net/detail/toss156/4350495


你可能感兴趣的:(【IOS】实现一种书本的展示特效)