blob: 7362e0901fcc773b94ae1084cae7c9be350feadb (
plain)
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
|
// -*- Mode: Objective-C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
//
// This file is part of the LibreOffice project.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import "MLOCommon.h"
#import "MLOSubView.h"
#import <QuartzCore/QuartzCore.h>
#define SIZE_CASE(CASE,RECT) case CASE: self.frame = self.bounds = RECT;break;
static const CGFloat DEFAULT_FADE_DURAION= 1.0f;
@interface MLOSubView ()
@property CGRect defaultRect;
@end
@implementation MLOSubView
- (id)initWithFrame:(CGRect)frame color:(UIColor *) color cornerRadius:(CGFloat) cornerRadius alpha:(CGFloat) alpha
{
self = [super initWithFrame:frame];
if (self) {
self.defaultRect = frame;
self.backgroundColor = color;
self.fadeDuration = DEFAULT_FADE_DURAION;
if([self isLegalNewAlpha:alpha]){
self.alpha = alpha;
}
if(cornerRadius >= 0){
[self.layer setCornerRadius:cornerRadius];
[self.layer setMasksToBounds:YES];
}
}
return self;
}
- (id)initHiddedWithColor:(UIColor *) color cornerRadius:(CGFloat) cornerRadius{
return [self initWithFrame:CGRECT_ZERO color:color cornerRadius:cornerRadius alpha: 0.0f];
}
- (id)initHiddedWithColor:(UIColor *) color{
return [self initHiddedWithColor:color cornerRadius:-1.0f];
}
-(BOOL)isLegalNewAlpha:(CGFloat) alpha{
return (alpha>=0) && (alpha<=1) && (alpha!= self.alpha);
}
-(void)fade:(MLOFadeType) type{
CGFloat alpha;
switch (type) {
case IN: alpha = 1.0f; break;
case OUT: alpha = 0.0f; break;
}
[self fadeToPercent:alpha];
}
-(void)setSize:(MLORectSize) size{
switch(size){
SIZE_CASE(ZERO, CGRECT_ZERO)
SIZE_CASE(ONE, CGRECT_ONE)
SIZE_CASE(INITIAL, _defaultRect)
SIZE_CASE(FULL_SCREEN, [[UIApplication sharedApplication] keyWindow].frame)
}
}
-(void) hide{
self.alpha=0;
[self setSize:ZERO];
}
-(void)fadeToPercent:(CGFloat) toPercent{
if([self isLegalNewAlpha:toPercent]){
[UIView animateWithDuration:1.0 animations:^{
self.alpha = toPercent;
}];
}
}
@end
|