Browse Source

首页切换动画效果

Steven 11 months ago
parent
commit
41831798f7

+ 1 - 0
KulexiuForStudent/KulexiuForStudent/AppDelegate.m

@@ -162,6 +162,7 @@
 }
 
 - (void)configRootVC {
+
     BOOL hasLaunchGuide = UserDefaultBoolForKey(FIRST_LOGIN_KEY);
     if (hasLaunchGuide == NO) {
         GuideViewController *guideVC = [[GuideViewController alloc] init];

+ 1 - 0
KulexiuForStudent/KulexiuForStudent/InstitutionModule/Home/Controller/TenantDarkViewController.m

@@ -375,6 +375,7 @@
 }
 
 - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
+
     BOOL isLock = self.tenantAlbumStatus == YES ? NO : YES;
     if (isLock) {
         TenantAlbumModel *model = self.sourceArray[index];

+ 39 - 11
KulexiuForStudent/KulexiuForStudent/InstitutionModule/Home/View/TenantSwitchAlbum/AlbumSwitchView.m

@@ -11,6 +11,9 @@
 #define ROW_HEIGHT (80)
 
 @interface AlbumSwitchView ()<UITableViewDelegate, UITableViewDataSource,UIGestureRecognizerDelegate>
+
+@property (weak, nonatomic) IBOutlet UIView *colorView;
+
 @property (weak, nonatomic) IBOutlet UIView *backView;
 
 @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpace;
@@ -44,13 +47,11 @@
     gesture.delegate = self;
     [self addGestureRecognizer:gesture];
     self.backViewTop.constant = -300.0f;
+    self.colorView.backgroundColor = HexRGBAlpha(0x000000, 0.6f);
 }
 
 - (void)cancelSwitchAlbum {
-    if (self.callback) {
-        self.callback(ALBUMSWITCH_TYPE_CANCLE, 0);
-    }
-    [self removeFromSuperview];
+    [self hideActionSwitch:NO];
 }
 
 
@@ -68,12 +69,31 @@
     [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.right.top.bottom.mas_equalTo(self.albumContainer);
     }];
+    [self layoutIfNeeded]; // 约束立刻生效
+    // 动画
     [self showAnimation];
 }
 
 - (void)showAnimation {
-    [UIView animateWithDuration:0.5f animations:^{
-        self.backViewTop.constant = 0.0f;
+    self.backViewTop.constant = 0;
+    [UIView animateWithDuration:0.3f animations:^{
+        [self layoutIfNeeded];
+    } completion:^(BOOL finished) {
+        
+    }];
+}
+
+- (void)hideAnimation {
+    self.colorView.backgroundColor = [UIColor clearColor];
+    NSInteger maxCountDisplay = self.sourceArray.count;
+    if (self.sourceArray.count > 5) {
+        maxCountDisplay = 5;
+    }
+    self.backViewTop.constant = -43 - maxCountDisplay * ROW_HEIGHT;
+    [UIView animateWithDuration:0.3f animations:^{
+        [self layoutIfNeeded];
+    } completion:^(BOOL finished) {
+        [self removeFromSuperview];
     }];
 }
 
@@ -123,15 +143,23 @@
     }
     self.lastChooseIndex = indexPath.row + 1000;
     [self.tableView reloadData];
-//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-        if (self.callback) {
+    
+    [self hideActionSwitch:YES];
+}
+
+- (void)hideActionSwitch:(BOOL)isModify {
+    if (self.callback) {
+        if (isModify == NO) {
+            self.callback(ALBUMSWITCH_TYPE_CANCLE, 0);
+        }
+        else {
             self.callback(ALBUMSWITCH_TYPE_SWITCH, self.lastChooseIndex-1000);
         }
-        [self removeFromSuperview];
-//    });
+    }
+    
+    [self hideAnimation];
 }
 
-
 #pragma mark ----- gesture delegate
 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
     if ([touch.view isDescendantOfView:self.backView]) {

+ 4 - 3
KulexiuForStudent/KulexiuForStudent/InstitutionModule/Home/View/TenantSwitchAlbum/AlbumSwitchView.xib

@@ -13,10 +13,10 @@
             <rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
             <autoresizingMask key="autoresizingMask"/>
             <subviews>
-                <view userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8QR-3U-ffM">
+                <view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8QR-3U-ffM">
                     <rect key="frame" x="0.0" y="88" width="393" height="764"/>
                     <subviews>
-                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2YN-MK-RCa">
+                        <view autoresizesSubviews="NO" clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2YN-MK-RCa">
                             <rect key="frame" x="0.0" y="0.0" width="393" height="300"/>
                             <subviews>
                                 <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="albumSwitch_title" translatesAutoresizingMaskIntoConstraints="NO" id="fVg-KR-avN">
@@ -26,7 +26,7 @@
                                         <constraint firstAttribute="height" constant="16" id="m8N-rt-QCU"/>
                                     </constraints>
                                 </imageView>
-                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ksc-u8-IFd">
+                                <view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ksc-u8-IFd">
                                     <rect key="frame" x="0.0" y="43" width="393" height="249"/>
                                     <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                     <constraints>
@@ -67,6 +67,7 @@
                 <outlet property="albumContainer" destination="ksc-u8-IFd" id="vRO-BG-y00"/>
                 <outlet property="backView" destination="2YN-MK-RCa" id="cWA-lQ-IRi"/>
                 <outlet property="backViewTop" destination="Oij-6z-tNR" id="p2w-zh-zqe"/>
+                <outlet property="colorView" destination="8QR-3U-ffM" id="MpM-xt-9R6"/>
                 <outlet property="containerHeight" destination="6x3-5k-UIG" id="I88-kY-pvV"/>
                 <outlet property="topSpace" destination="GXL-9e-sT5" id="NGK-Gz-yFM"/>
             </connections>