-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGuideView.m
100 lines (88 loc) · 3.12 KB
/
GuideView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// GuideView.m
//
//
// Created by Cloay on 12-9-18.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "GuideView.h"
@implementation GuideView
@synthesize imageView;
@synthesize pageScroll;
@synthesize pageControl;
@synthesize closeButton;
@synthesize startButton;
@synthesize left;
@synthesize right;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
[self.pageScroll setContentSize:CGSizeMake(1600, 0)];
[self.pageScroll setDelegate:self];
float y = DEVICE_IS_IPHONE5 ? 510 : 425;
[self.pageControl setFrame:CGRectMake(110, y, 100, 36)];
}
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
if ([animationID isEqualToString:@"split"] && finished) {
[self.left removeFromSuperview];
[self.right removeFromSuperview];
}
[self removeFromSuperview];
}
- (IBAction)startButtonDidPressed:(id)sender{
[self.startButton setHidden:YES];
NSArray *array = [UIImage splitImageIntoTwoParts:self.imageView.image];
self.left = [[UIImageView alloc] initWithImage:[array objectAtIndex:0]];
float height = DEVICE_IS_IPHONE5 ? 568 : 480;
[self.left setFrame:CGRectMake(0, 0, 320, height)];
self.right = [[UIImageView alloc] initWithImage:[array objectAtIndex:1]];
[self.right setFrame:CGRectMake(0, 0, 320, height)];
[self addSubview:self.left];
[self addSubview:self.right];
[self.pageScroll setHidden:YES];
[self.pageControl setHidden:YES];
self.left.transform = CGAffineTransformIdentity;
self.right.transform = CGAffineTransformIdentity;
[UIView beginAnimations:@"split" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.2];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[self.left setAlpha:0.15];
[self.right setAlpha:0.15];
self.left.transform = CGAffineTransformMakeTranslation(-180 ,0);
self.right.transform = CGAffineTransformMakeTranslation(180 ,0);
[UIView commitAnimations];
}
- (IBAction)closeButtonDidPressed:(id)sender{
[UIView beginAnimations:@"Close" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.6];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[self setAlpha:0.15];
[UIView commitAnimations];
}
#pragma mark -
#pragma mark scrollview delegate method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat pageWidth = self.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
if (page < 4) {
[closeButton setHidden:NO];
}else {
[closeButton setHidden:YES];
}
pageControl.currentPage = page;
}
@end