Skip to content

Commit a62b17b

Browse files
committed
add dropdown animation
1 parent cfcc40b commit a62b17b

File tree

8 files changed

+153
-8
lines changed

8 files changed

+153
-8
lines changed

TYAlertControllerDemo.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
B01449081BDE5817009E0389 /* ShareView.xib in Resources */ = {isa = PBXBuildFile; fileRef = B01449071BDE5817009E0389 /* ShareView.xib */; };
1616
B0873F0D1BD370C700D2F4D5 /* TYShowAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = B0873F0C1BD370C700D2F4D5 /* TYShowAlertView.m */; };
1717
B08FD7D01BD905EF00B83FF5 /* screen.jpg in Resources */ = {isa = PBXBuildFile; fileRef = B08FD7CF1BD905EF00B83FF5 /* screen.jpg */; };
18+
B0D617E41BDF9C5D0084EE84 /* TYAlertDropDownAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = B0D617E31BDF9C5D0084EE84 /* TYAlertDropDownAnimation.m */; };
1819
D35854241B9532D700B5FA1F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D35854231B9532D700B5FA1F /* main.m */; };
1920
D35854271B9532D700B5FA1F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D35854261B9532D700B5FA1F /* AppDelegate.m */; };
2021
D358542A1B9532D700B5FA1F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D35854291B9532D700B5FA1F /* ViewController.m */; };
@@ -56,6 +57,8 @@
5657
B0873F0B1BD370C700D2F4D5 /* TYShowAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TYShowAlertView.h; sourceTree = "<group>"; };
5758
B0873F0C1BD370C700D2F4D5 /* TYShowAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TYShowAlertView.m; sourceTree = "<group>"; };
5859
B08FD7CF1BD905EF00B83FF5 /* screen.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = screen.jpg; sourceTree = "<group>"; };
60+
B0D617E21BDF9C5D0084EE84 /* TYAlertDropDownAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TYAlertDropDownAnimation.h; sourceTree = "<group>"; };
61+
B0D617E31BDF9C5D0084EE84 /* TYAlertDropDownAnimation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TYAlertDropDownAnimation.m; sourceTree = "<group>"; };
5962
D358541E1B9532D700B5FA1F /* TYAlertControllerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TYAlertControllerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
6063
D35854221B9532D700B5FA1F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6164
D35854231B9532D700B5FA1F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
@@ -214,6 +217,8 @@
214217
D35854A81B95973000B5FA1F /* TYAlertFadeAnimation.m */,
215218
D395FE1D1B96C7F1000F72F7 /* TYAlertScaleFadeAnimation.h */,
216219
D395FE1E1B96C7F1000F72F7 /* TYAlertScaleFadeAnimation.m */,
220+
B0D617E21BDF9C5D0084EE84 /* TYAlertDropDownAnimation.h */,
221+
B0D617E31BDF9C5D0084EE84 /* TYAlertDropDownAnimation.m */,
217222
);
218223
name = AlertAimations;
219224
sourceTree = "<group>";
@@ -340,6 +345,7 @@
340345
B01448F71BDE50C1009E0389 /* UIImage+ImageEffects.m in Sources */,
341346
B01449061BDE57E9009E0389 /* ShareView.m in Sources */,
342347
D35854B51B95B7BB00B5FA1F /* TYBaseAnimation.m in Sources */,
348+
B0D617E41BDF9C5D0084EE84 /* TYAlertDropDownAnimation.m in Sources */,
343349
D3C1A9761B9D1A83009738B0 /* TYAlertView.m in Sources */,
344350
D37A91E11B9E7B6000C6661A /* UIView+TYAutoLayout.m in Sources */,
345351
D35854271B9532D700B5FA1F /* AppDelegate.m in Sources */,

TYAlertControllerDemo/Base.lproj/Main.storyboard

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</userDefinedRuntimeAttributes>
2828
</imageView>
2929
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Yfr-BX-DRT">
30-
<rect key="frame" x="230" y="268" width="140" height="30"/>
30+
<rect key="frame" x="230" y="304" width="140" height="30"/>
3131
<animations/>
3232
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
3333
<constraints>
@@ -53,7 +53,7 @@
5353
</connections>
5454
</button>
5555
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vCS-SU-E0R">
56-
<rect key="frame" x="222" y="100" width="156" height="30"/>
56+
<rect key="frame" x="222" y="80" width="156" height="30"/>
5757
<animations/>
5858
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
5959
<constraints>
@@ -79,7 +79,7 @@
7979
</connections>
8080
</button>
8181
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Pbc-5y-GLg">
82-
<rect key="frame" x="255" y="212" width="91" height="30"/>
82+
<rect key="frame" x="255" y="248" width="91" height="30"/>
8383
<animations/>
8484
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
8585
<constraints>
@@ -99,7 +99,7 @@
9999
</connections>
100100
</button>
101101
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1WY-V3-iTv">
102-
<rect key="frame" x="229" y="338" width="142" height="30"/>
102+
<rect key="frame" x="229" y="366" width="142" height="30"/>
103103
<animations/>
104104
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
105105
<constraints>
@@ -117,7 +117,7 @@
117117
</connections>
118118
</button>
119119
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4z7-Ic-djO">
120-
<rect key="frame" x="230" y="156" width="140" height="30"/>
120+
<rect key="frame" x="230" y="136" width="140" height="30"/>
121121
<animations/>
122122
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
123123
<constraints>
@@ -143,7 +143,7 @@
143143
</connections>
144144
</button>
145145
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gdy-Yw-9Yd">
146-
<rect key="frame" x="222" y="394" width="156" height="30"/>
146+
<rect key="frame" x="222" y="422" width="156" height="30"/>
147147
<animations/>
148148
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
149149
<constraints>
@@ -160,6 +160,32 @@
160160
<action selector="customViewInWindowAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="R4A-2L-y6S"/>
161161
</connections>
162162
</button>
163+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="eW6-OK-8kA">
164+
<rect key="frame" x="230" y="192" width="140" height="30"/>
165+
<animations/>
166+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
167+
<constraints>
168+
<constraint firstAttribute="width" constant="91" id="D7q-Dl-FcW"/>
169+
<constraint firstAttribute="height" constant="30" id="hBd-hI-ORF"/>
170+
<constraint firstAttribute="width" constant="140" id="khf-YV-8E6"/>
171+
</constraints>
172+
<state key="normal" title="dropdownAnimation">
173+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
174+
</state>
175+
<userDefinedRuntimeAttributes>
176+
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
177+
<integer key="value" value="5"/>
178+
</userDefinedRuntimeAttribute>
179+
</userDefinedRuntimeAttributes>
180+
<variation key="default">
181+
<mask key="constraints">
182+
<exclude reference="D7q-Dl-FcW"/>
183+
</mask>
184+
</variation>
185+
<connections>
186+
<action selector="dropdwonAnimationAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="ALD-sJ-Ayh"/>
187+
</connections>
188+
</button>
163189
</subviews>
164190
<animations/>
165191
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
@@ -168,30 +194,38 @@
168194
<constraint firstItem="1WY-V3-iTv" firstAttribute="top" secondItem="Yfr-BX-DRT" secondAttribute="bottom" constant="40" id="5eB-EE-r5Z"/>
169195
<constraint firstItem="gdy-Yw-9Yd" firstAttribute="top" secondItem="1WY-V3-iTv" secondAttribute="bottom" constant="26" id="6EW-lt-A1G"/>
170196
<constraint firstAttribute="trailing" secondItem="k0k-Qy-0Gy" secondAttribute="trailing" id="8ry-Au-szq"/>
197+
<constraint firstItem="Pbc-5y-GLg" firstAttribute="top" secondItem="eW6-OK-8kA" secondAttribute="bottom" constant="26" id="90E-AS-f3p"/>
171198
<constraint firstItem="Yfr-BX-DRT" firstAttribute="top" secondItem="Pbc-5y-GLg" secondAttribute="bottom" constant="42" id="9NA-YE-ipl"/>
172199
<constraint firstItem="k0k-Qy-0Gy" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Abd-iC-uZ3"/>
173200
<constraint firstItem="4z7-Ic-djO" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Avw-oo-VhF"/>
174201
<constraint firstItem="k0k-Qy-0Gy" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="N7f-Z7-qps"/>
175202
<constraint firstItem="Yfr-BX-DRT" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="SDo-Pv-z7k"/>
176203
<constraint firstItem="4z7-Ic-djO" firstAttribute="top" secondItem="Pbc-5y-GLg" secondAttribute="bottom" constant="26" id="T0j-64-O2J"/>
177204
<constraint firstItem="gdy-Yw-9Yd" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="T7x-xC-FFp"/>
205+
<constraint firstItem="1WY-V3-iTv" firstAttribute="top" secondItem="Yfr-BX-DRT" secondAttribute="bottom" constant="32" id="UDZ-4u-gji"/>
206+
<constraint firstItem="eW6-OK-8kA" firstAttribute="top" secondItem="4z7-Ic-djO" secondAttribute="bottom" constant="26" id="V6b-6s-ZkB"/>
178207
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="k0k-Qy-0Gy" secondAttribute="bottom" id="VGn-hG-lI4"/>
179208
<constraint firstItem="Yfr-BX-DRT" firstAttribute="top" secondItem="4z7-Ic-djO" secondAttribute="bottom" constant="26" id="WK2-CA-DMO"/>
180209
<constraint firstItem="Pbc-5y-GLg" firstAttribute="top" secondItem="vCS-SU-E0R" secondAttribute="bottom" constant="28" id="XMM-Dk-17g"/>
210+
<constraint firstItem="eW6-OK-8kA" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="cd6-Td-Rb9"/>
181211
<constraint firstItem="4z7-Ic-djO" firstAttribute="top" secondItem="vCS-SU-E0R" secondAttribute="bottom" constant="26" id="dOh-xc-Qeq"/>
182212
<constraint firstItem="k0k-Qy-0Gy" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="g1Y-r6-VZe"/>
183213
<constraint firstItem="1WY-V3-iTv" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="g2R-k6-tZu"/>
184-
<constraint firstItem="vCS-SU-E0R" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="80" id="gTK-jF-eL0"/>
214+
<constraint firstItem="eW6-OK-8kA" firstAttribute="top" secondItem="Yfr-BX-DRT" secondAttribute="bottom" constant="26" id="g4P-fl-Fu3"/>
215+
<constraint firstItem="vCS-SU-E0R" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="60" id="gTK-jF-eL0"/>
185216
<constraint firstItem="Pbc-5y-GLg" firstAttribute="top" secondItem="4z7-Ic-djO" secondAttribute="bottom" constant="26" id="kga-I8-ALT"/>
186217
<constraint firstAttribute="centerX" secondItem="Pbc-5y-GLg" secondAttribute="centerX" id="mBu-C3-nZu"/>
187218
<constraint firstAttribute="centerX" secondItem="vCS-SU-E0R" secondAttribute="centerX" id="tYU-co-tHf"/>
188219
</constraints>
189220
<variation key="default">
190221
<mask key="constraints">
191222
<exclude reference="T0j-64-O2J"/>
223+
<exclude reference="g4P-fl-Fu3"/>
192224
<exclude reference="XMM-Dk-17g"/>
225+
<exclude reference="kga-I8-ALT"/>
193226
<exclude reference="9NA-YE-ipl"/>
194227
<exclude reference="WK2-CA-DMO"/>
228+
<exclude reference="5eB-EE-r5Z"/>
195229
</mask>
196230
</variation>
197231
</view>

TYAlertControllerDemo/TYAlertController/TYAlertController+TransitionAnimate.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "TYAlertController.h"
1010
#import "TYAlertFadeAnimation.h"
1111
#import "TYAlertScaleFadeAnimation.h"
12+
#import "TYAlertDropDownAnimation.h"
1213

1314
@implementation TYAlertController (TransitionAnimate)
1415

@@ -21,6 +22,8 @@ @implementation TYAlertController (TransitionAnimate)
2122
return [TYAlertFadeAnimation alertAnimationIsPresenting:YES];
2223
case TYAlertTransitionAnimationScaleFade:
2324
return [TYAlertScaleFadeAnimation alertAnimationIsPresenting:YES];
25+
case TYAlertTransitionAnimationDropDown:
26+
return [TYAlertDropDownAnimation alertAnimationIsPresenting:YES];
2427
case TYAlertTransitionAnimationCustom:
2528
return [self.class alertAnimationIsPresenting:YES preferredStyle:self.preferredStyle];
2629
default:
@@ -35,6 +38,8 @@ @implementation TYAlertController (TransitionAnimate)
3538
return [TYAlertFadeAnimation alertAnimationIsPresenting:NO];
3639
case TYAlertTransitionAnimationScaleFade:
3740
return [TYAlertScaleFadeAnimation alertAnimationIsPresenting:NO];
41+
case TYAlertTransitionAnimationDropDown:
42+
return [TYAlertDropDownAnimation alertAnimationIsPresenting:NO];
3843
case TYAlertTransitionAnimationCustom:
3944
return [self.class alertAnimationIsPresenting:NO preferredStyle:self.preferredStyle];
4045
default:

TYAlertControllerDemo/TYAlertController/TYAlertController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef NS_ENUM(NSInteger, TYAlertControllerStyle) {
1717
typedef NS_ENUM(NSInteger, TYAlertTransitionAnimation) {
1818
TYAlertTransitionAnimationFade = 0,
1919
TYAlertTransitionAnimationScaleFade,
20+
TYAlertTransitionAnimationDropDown,
2021
TYAlertTransitionAnimationCustom
2122
};
2223

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// TYAlertDropDownAnimation.h
3+
// TYAlertControllerDemo
4+
//
5+
// Created by tanyang on 15/10/27.
6+
// Copyright © 2015年 tanyang. All rights reserved.
7+
//
8+
9+
#import "TYBaseAnimation.h"
10+
11+
@interface TYAlertDropDownAnimation : TYBaseAnimation
12+
13+
@end
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// TYAlertDropDownAnimation.m
3+
// TYAlertControllerDemo
4+
//
5+
// Created by tanyang on 15/10/27.
6+
// Copyright © 2015年 tanyang. All rights reserved.
7+
//
8+
9+
#import "TYAlertDropDownAnimation.h"
10+
11+
@implementation TYAlertDropDownAnimation
12+
13+
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
14+
{
15+
if (self.isPresenting) {
16+
return 0.5;
17+
}
18+
return 0.25;
19+
}
20+
21+
- (void)presentAnimateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
22+
{
23+
TYAlertController *alertController = (TYAlertController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
24+
25+
alertController.backgroundView.alpha = 0.0;
26+
27+
switch (alertController.preferredStyle) {
28+
case TYAlertControllerStyleAlert:
29+
alertController.alertView.transform = CGAffineTransformMakeTranslation(0, -CGRectGetMaxY(alertController.alertView.frame));
30+
break;
31+
case TYAlertControllerStyleActionSheet:
32+
NSLog(@"don't support ActionSheet style!");
33+
break;
34+
default:
35+
break;
36+
}
37+
38+
UIView *containerView = [transitionContext containerView];
39+
[containerView addSubview:alertController.view];
40+
41+
[UIView animateWithDuration:0.5 delay:0.0 usingSpringWithDamping:0.65 initialSpringVelocity:0.5 options:0 animations:^{
42+
43+
alertController.backgroundView.alpha = 1.0;
44+
alertController.alertView.transform = CGAffineTransformIdentity;
45+
46+
} completion:^(BOOL finished) {
47+
[transitionContext completeTransition:YES];
48+
}];
49+
}
50+
51+
- (void)dismissAnimateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
52+
{
53+
TYAlertController *alertController = (TYAlertController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
54+
55+
[UIView animateWithDuration:0.25 animations:^{
56+
alertController.backgroundView.alpha = 0.0;
57+
switch (alertController.preferredStyle) {
58+
case TYAlertControllerStyleAlert:
59+
alertController.alertView.alpha = 0.0;
60+
alertController.alertView.transform = CGAffineTransformMakeScale(0.9, 0.9);
61+
break;
62+
case TYAlertControllerStyleActionSheet:
63+
NSLog(@"don't support ActionSheet style!");
64+
break;
65+
default:
66+
break;
67+
}
68+
} completion:^(BOOL finished) {
69+
[transitionContext completeTransition:YES];
70+
}];
71+
}
72+
73+
@end

TYAlertControllerDemo/TYAlertController/TYBaseAnimation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@interface TYBaseAnimation : NSObject<UIViewControllerAnimatedTransitioning>
1313

14-
@property (nonatomic, assign, readonly) BOOL isPresenting;
14+
@property (nonatomic, assign, readonly) BOOL isPresenting; // present . dismiss
1515

1616
+ (instancetype)alertAnimationIsPresenting:(BOOL)isPresenting;
1717

0 commit comments

Comments
 (0)