亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

iOS開(kāi)發(fā)實(shí)現(xiàn)抽屜效果

 更新時(shí)間:2022年08月08日 10:40:53   作者:Yeppppppppp  
這篇文章主要為大家詳細(xì)介紹了iOS開(kāi)發(fā)實(shí)現(xiàn)抽屜效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

iOS開(kāi)發(fā)之如何實(shí)現(xiàn)“抽屜”效果,供大家參考,具體內(nèi)容如下

現(xiàn)在基本上每一個(gè)App中左劃都會(huì)出現(xiàn)一個(gè)頁(yè)面,基本上都是只占主頁(yè)面的一部分,效果就像是一個(gè)抽屜一樣。最近在寫(xiě)項(xiàng)目時(shí),關(guān)于如何達(dá)到抽屜效果,總結(jié)了一些東西。
先看看效果圖:

實(shí)現(xiàn)過(guò)程

首先我們需要去創(chuàng)建一個(gè)新的視圖控制器,讓它作為我們的要實(shí)現(xiàn)的抽屜的根視圖,在此視圖控制器我們要添加對(duì)應(yīng)的左視圖,要是需要右視圖也可以添加,然后設(shè)定方法:

@property (nonatomic, strong) UIViewController *rootViewController;
//左側(cè)視圖
@property (nonatomic, strong) UIViewController *leftViewController;
//菜單寬度
@property (nonatomic, assign, readonly) CGFloat menuWidth;
//留白寬度
@property (nonatomic, assign, readonly) CGFloat emptyWidth;
//是否允許滾動(dòng)
@property (nonatomic ,assign) BOOL slideEnabled;
//創(chuàng)建方法
-(instancetype)initWithRootViewController:(UIViewController*)rootViewController;
//顯示主視圖
-(void)showRootViewControllerAnimated:(BOOL)animated;
//顯示左側(cè)菜單
-(void)showLeftViewControllerAnimated:(BOOL)animated;

接著我們將定義的方法進(jìn)行實(shí)現(xiàn):

-(instancetype)initWithRootViewController:(UIViewController*)rootViewController{
? ? if (self = [super init]) {
? ? ? ? _rootViewController = rootViewController;
? ? ? ? [self addChildViewController:_rootViewController];
? ? ? ? [self.view addSubview:_rootViewController.view];
? ? ? ? [_rootViewController didMoveToParentViewController:self];
? ? }
? ? return self;
}

- (void)showLeftViewControllerAnimated:(BOOL)animated {
? ? if (!_leftViewController) {return;}
? ? [self.view sendSubviewToBack:_rightViewController.view];
? ? _coverView.hidden = false;
? ? [_rootViewController.view bringSubviewToFront:_coverView];
? ? [UIView animateWithDuration:[self animationDurationAnimated:animated] animations:^{
? ? ? ? _rootViewController.view.center = CGPointMake(_rootViewController.view.bounds.size.width/2 + self.menuWidth, _rootViewController.view.center.y);
? ? ? ? _leftViewController.view.frame = CGRectMake(0, 0, [self menuWidth], self.view.bounds.size.height);
? ? ? ? _coverView.alpha = MaxCoverAlpha;
? ? }];
}

然后我們需要添加一個(gè)分類(lèi),讓它向前聲明新的視圖控制器,添加一個(gè)創(chuàng)建視圖的方法使用懶加載:

- (XLSlideMenuViewController *)xl_sldeMenu {
? ? UIViewController *sldeMenu = self.parentViewController;
? ? while (sldeMenu) {
? ? ? ? if ([sldeMenu isKindOfClass:[XLSlideMenuViewController class]]) {
? ? ? ? ? ? return (XLSlideMenuViewController *)sldeMenu;
? ? ? ? } else if (sldeMenu.parentViewController && sldeMenu.parentViewController != sldeMenu) {
? ? ? ? ? ? sldeMenu = sldeMenu.parentViewController;
? ? ? ? } else {
? ? ? ? ? ? sldeMenu = nil;
? ? ? ? }
? ? }
? ? return nil;
}

然后我們?cè)谑褂贸閷系臅r(shí)候,需要西安去設(shè)置根視圖,然后將左側(cè)視圖初始化并將左視圖添加在前邊設(shè)置好的左視圖屬性上:

UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:tabBarControllerTest];
? ? nav.modalPresentationStyle = UIModalPresentationFullScreen;
? ??
? ? LeftViewController *leftVC = [[LeftViewController alloc] init];
? ? XLSlideMenuViewController *slideMenu = [[XLSlideMenuViewController alloc] initWithRootViewController:nav];
? ? slideMenu.leftViewController = leftVC;
? ? self.window.rootViewController = slideMenu;
? ? slideMenu.modalPresentationStyle = UIModalPresentationFullScreen;
? ? [self presentViewController:slideMenu animated:NO completion:nil];

最后在我們還可以添加點(diǎn)擊事件,并且添加拖拽方法,使操作更加簡(jiǎn)單:

-(void)panChanged:(UIPanGestureRecognizer*)pan{
? ? //拖拽的距離
? ? CGPoint translation = [pan translationInView:self.view];
? ? //移動(dòng)主控制器
? ? _rootViewController.view.center = CGPointMake(_originalPoint.x + translation.x, _originalPoint.y);
? ? //判斷是否設(shè)置了左右菜單
? ? if (!_rightViewController && CGRectGetMinX(_rootViewController.view.frame) <= 0 ) {
? ? ? ? _rootViewController.view.frame = self.view.bounds;
? ? }
? ? if (!_leftViewController && CGRectGetMinX(_rootViewController.view.frame) >= 0) {
? ? ? ? _rootViewController.view.frame = self.view.bounds;
? ? }
? ? //滑動(dòng)到邊緣位置后不可以繼續(xù)滑動(dòng)
? ? if (CGRectGetMinX(_rootViewController.view.frame) > self.menuWidth) {
? ? ? ? _rootViewController.view.center = CGPointMake(_rootViewController.view.bounds.size.width/2 + self.menuWidth, _rootViewController.view.center.y);
? ? }
? ? if (CGRectGetMaxX(_rootViewController.view.frame) < self.emptyWidth) {
? ? ? ? _rootViewController.view.center = CGPointMake(_rootViewController.view.bounds.size.width/2 - self.menuWidth, _rootViewController.view.center.y);
? ? }
? ? //判斷顯示左菜單還是右菜單
? ? if (CGRectGetMinX(_rootViewController.view.frame) > 0) {
? ? ? ? //顯示左菜單
? ? ? ? [self.view sendSubviewToBack:_rightViewController.view];
? ? ? ? //更新左菜單位置
? ? ? ? [self updateLeftMenuFrame];
? ? ? ? //更新遮罩層的透明度
? ? ? ? _coverView.hidden = false;
? ? ? ? [_rootViewController.view bringSubviewToFront:_coverView];
? ? ? ? _coverView.alpha = CGRectGetMinX(_rootViewController.view.frame)/self.menuWidth * MaxCoverAlpha;
? ? }else if (CGRectGetMinX(_rootViewController.view.frame) < 0){
? ? ? ??
? ? ? ? //更新遮罩層的透明度
? ? ? ? _coverView.hidden = false;
? ? ? ? [_rootViewController.view bringSubviewToFront:_coverView];
? ? ? ? _coverView.alpha = (CGRectGetMaxX(self.view.frame) - CGRectGetMaxX(_rootViewController.view.frame))/self.menuWidth * MaxCoverAlpha;
? ? }
}

然后左視圖中的具體內(nèi)容我們就可以自己去設(shè)置了,這樣就達(dá)到了一個(gè)“抽屜”的效果。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS實(shí)現(xiàn)簡(jiǎn)易的抽屜效果

    iOS實(shí)現(xiàn)簡(jiǎn)易的抽屜效果

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)簡(jiǎn)易的抽屜效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • 淺談iOS解析HTMl標(biāo)簽以及開(kāi)發(fā)中的一些坑

    淺談iOS解析HTMl標(biāo)簽以及開(kāi)發(fā)中的一些坑

    這篇文章主要介紹了淺談iOS解析HTMl標(biāo)簽以及開(kāi)發(fā)中的一些坑,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • Swift 進(jìn)階 —— map 和 flatMap的使用

    Swift 進(jìn)階 —— map 和 flatMap的使用

    這篇文章主要介紹了Swift map和flatMap的相關(guān)資料,幫助大家更好的理解和使用Swift,感興趣的朋友可以了解下
    2020-09-09
  • iOS WebView中使用webp格式圖片的方法

    iOS WebView中使用webp格式圖片的方法

    由于最近項(xiàng)目需求,需要將項(xiàng)目中圖片的加載做到同時(shí)兼容WebP格式,所以下面這篇文章主要給大家介紹了關(guān)于在iOS WebView中使用webp格式圖片的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2018-05-05
  • iOS中鍵盤(pán) KeyBoard 上添加工具欄的方法

    iOS中鍵盤(pán) KeyBoard 上添加工具欄的方法

    大iOS中 鍵盤(pán) KeyBoard 上怎么添加工具欄呢?大致思路是提前創(chuàng)建好工具欄,在鍵盤(pán)彈出的時(shí)候?qū)⒐ぞ邫陲@示出來(lái),在鍵盤(pán)消失的時(shí)候讓工具欄隱藏。具體實(shí)現(xiàn)代碼大家參考下本文吧
    2017-08-08
  • IOS面試大全之常見(jiàn)算法

    IOS面試大全之常見(jiàn)算法

    之前看了很多面試題,感覺(jué)要不是不夠就是過(guò)于冗余,于是我將網(wǎng)上的一些面試題進(jìn)行了刪減和分類(lèi),這篇文章先給大家分享一下IOS中的常見(jiàn)算法,有需要的可以參考借鑒。
    2016-09-09
  • iOS tableView實(shí)現(xiàn)下拉圖片放大效果

    iOS tableView實(shí)現(xiàn)下拉圖片放大效果

    這篇文章主要為大家詳細(xì)介紹了iOS tableView實(shí)現(xiàn)下拉圖片放大效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • iOS利用攝像頭獲取環(huán)境光感參數(shù)的方法

    iOS利用攝像頭獲取環(huán)境光感參數(shù)的方法

    本篇文章主要介紹了iOS利用攝像頭獲取環(huán)境光感參數(shù)的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11
  • iOS鍵盤(pán)彈出遮擋輸入框的解決方法

    iOS鍵盤(pán)彈出遮擋輸入框的解決方法

    這篇文章主要為大家詳細(xì)介紹了iOS鍵盤(pán)彈出遮擋輸入框的解決方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • 詳解iOS使用Keychain中的kSecClassGenericPassword存儲(chǔ)數(shù)據(jù)

    詳解iOS使用Keychain中的kSecClassGenericPassword存儲(chǔ)數(shù)據(jù)

    iOS設(shè)備中的Keychain是一個(gè)安全的存儲(chǔ)容器,本篇文章主要介紹了iOS使用Keychain中的kSecClassGenericPassword存儲(chǔ)數(shù)據(jù),有興趣的可以了解一下。
    2016-11-11

最新評(píng)論