国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS如何用100行代碼實現簡單的抽屜效果

2020-07-26 03:07:39
字體:
來源:轉載
供稿:網友

前言

iOS中抽屜效果的簡單實現現在很多應用中都使用到了,網上也有很多了例子,本文主要是通過簡單的一些代碼來實現的,有需要的可以一起學習學習。

下面是效果圖

示例代碼如下

#import <UIKit/UIKit.h>@interface MainViewController : UIViewController+ (instancetype)mainViewControllerWithLeftViewController:(UIViewController *)leftViewController withMainPageViewController:(UIViewController *)mainPageViewController;@end
#import "MainViewController.h"#define KWidth self.view.frame.size.width#define KHeight self.view.frame.size.height@interface MainViewController ()@property (nonatomic,strong)UIViewController *leftVC;@property (nonatomic,strong)UIViewController *centerVC;@property (nonatomic,assign)BOOL isSlider;@property (nonatomic,strong)UIView *corverView;@end@implementation MainViewController+ (instancetype)mainViewControllerWithLeftViewController:(UIViewController *)leftViewController withMainPageViewController:(UIViewController *)mainPageViewController{  MainViewController *mainVC = [[MainViewController alloc] init];  mainVC.leftVC = leftViewController;  mainVC.centerVC = mainPageViewController;  return mainVC;}- (void)viewDidLoad{  [super viewDidLoad];  self.isSlider = NO;  self.view.backgroundColor = [UIColor whiteColor];  [self addChildViewController:self.leftVC];  [self.view addSubview:self.leftVC.view];  [self addChildViewController:self.centerVC];  [self.view addSubview:self.centerVC.view];  // 給左視圖和主視圖添加手勢  [self addGestureForView];}// 給主視圖添加遮蓋- (void)addCorverView{  if (self.corverView) {    [self.corverView removeFromSuperview];    self.corverView = nil;  }  self.corverView = [[UIView alloc] initWithFrame:self.centerVC.view.bounds];  _corverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];  [self.centerVC.view addSubview:self.corverView];}// 移除主視圖遮蓋- (void)removeCoverView{  if (self.corverView) {    [self.corverView removeFromSuperview];    self.corverView = nil;  }}// 給左視圖和主視圖添加手勢- (void)addGestureForView{  UISwipeGestureRecognizer *rightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction:)];  rightGesture.direction = UISwipeGestureRecognizerDirectionRight;  [self.centerVC.view addGestureRecognizer:rightGesture];  UISwipeGestureRecognizer *leftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction:)];  leftGesture.direction = UISwipeGestureRecognizerDirectionLeft;  [self.centerVC.view addGestureRecognizer:leftGesture];  UISwipeGestureRecognizer *leftVCLeftSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftVCLeftSwipeAction:)];  leftVCLeftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;  [self.leftVC.view addGestureRecognizer:leftVCLeftSwipeGesture];}- (void)swipeRightAction:(id)sender{  [self moveView:self.centerVC.view scale:0.8 panValue:KWidth];  self.isSlider = YES;  [self addCorverView];}- (void)swipeLeftAction:(id)sender{  [self moveView:self.centerVC.view scale:1 panValue:KWidth / 2];  self.isSlider = NO;  [self removeCoverView];}- (void)leftVCLeftSwipeAction:(id)sender{  [self moveView:self.centerVC.view scale:1 panValue:KWidth / 2];  self.isSlider = NO;  [self removeCoverView];}// 平移和縮放一個視圖- (void)moveView:(UIView *)view scale:(CGFloat)scale panValue:(CGFloat)value{  [UIView beginAnimations:nil context:nil];  view.transform = CGAffineTransformScale(CGAffineTransformIdentity,scale,scale);  view.center = CGPointMake(value, view.center.y);  [UIView commitAnimations];}@end

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能有所幫助,如果有疑問大家可以留言交流。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 延津县| 峨边| 南部县| 宜君县| 怀集县| 新郑市| 工布江达县| 木兰县| 辽阳县| 安宁市| 涡阳县| 威远县| 开江县| 府谷县| 浦北县| 南安市| 武乡县| 永登县| 白河县| 抚顺县| 贞丰县| 阳泉市| 湘潭县| 满城县| 潍坊市| 仪陇县| 南川市| 莱阳市| 英山县| 綦江县| 云浮市| 马龙县| 奉节县| 郓城县| 南昌市| 临汾市| 安岳县| 哈密市| 乳山市| 高台县| 乌拉特后旗|