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

iOS如何用100行代碼實現(xiàn)簡單的抽屜效果

 更新時間:2016年10月28日 08:41:49   作者:LYSNote  
最近在網(wǎng)上看到一些抽屜效果,看起來很酷!很眩!但是,下不下來看代碼, 所以決定還是自己寫吧!!這篇文章通過近100行的代碼就實現(xiàn)了簡單的抽屜效果,有需要的朋友們可以參考借鑒,下面來一起看看吧。

前言

iOS中抽屜效果的簡單實現(xiàn)現(xiàn)在很多應(yīng)用中都使用到了,網(wǎng)上也有很多了例子,本文主要是通過簡單的一些代碼來實現(xiàn)的,有需要的可以一起學(xué)習(xí)學(xué)習(xí)。

下面是效果圖

示例代碼如下

#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

總結(jié)

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

相關(guān)文章

  • IOS百度地圖導(dǎo)航開發(fā)功能實現(xiàn)簡述

    IOS百度地圖導(dǎo)航開發(fā)功能實現(xiàn)簡述

    百度地圖導(dǎo)航非常實用,那么基于代碼是如何實現(xiàn)的呢,下面通過本文給大家介紹IOS百度地圖導(dǎo)航開發(fā)功能實現(xiàn)簡述,需要的朋友可以參考下本文
    2016-03-03
  • IOS開發(fā)中使用UIFont設(shè)置字體及批量創(chuàng)建控件

    IOS開發(fā)中使用UIFont設(shè)置字體及批量創(chuàng)建控件

    這篇文章主要介紹了IOS開發(fā)中使用UIFont設(shè)置字體及批量創(chuàng)建控件的方法,內(nèi)容很實用,感興趣的小伙伴們可以參考一下
    2016-03-03
  • 詳解iOS集成GoogleMap(定位、搜索)

    詳解iOS集成GoogleMap(定位、搜索)

    這篇文章主要介紹了iOS集成GoogleMap(定位、搜索)需要注意的地方,對此有興趣的讀者一起學(xué)習(xí)下吧。
    2018-02-02
  • IOS實現(xiàn)展開二級列表效果

    IOS實現(xiàn)展開二級列表效果

    本文通過實例代碼向大家演示在IOS中如何實現(xiàn)展開二級列表的效果,這個功能效果很好,對于日常開發(fā)APP中很有幫助,下面一起來看看如何實現(xiàn)吧。
    2016-08-08
  • iOS DispatchSourceTimer 定時器的具體使用

    iOS DispatchSourceTimer 定時器的具體使用

    定時器在很多地方都可以用到,本文主要介紹了iOS DispatchSourceTimer 定時器的具體使用,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • iOS 獲取公歷、農(nóng)歷日期的年月日的實例代碼

    iOS 獲取公歷、農(nóng)歷日期的年月日的實例代碼

    本篇文章主要介紹了iOS 獲取公歷、農(nóng)歷日期的年月日的實例代碼,主要介紹了三種方法,具有一定的參考價值,有興趣的可以了解一下。
    2017-02-02
  • iOS中的多線程如何按設(shè)定順序去執(zhí)行任務(wù)詳解

    iOS中的多線程如何按設(shè)定順序去執(zhí)行任務(wù)詳解

    多線程相信大家或多或少都有所了解吧,下面這篇文章主要給大家介紹了關(guān)于iOS中多線程如何按設(shè)定順序去執(zhí)行任務(wù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位iOS開發(fā)者們的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2017-12-12
  • iOS開發(fā)之UIScrollView控件詳解

    iOS開發(fā)之UIScrollView控件詳解

    UIScrollView是一個非常重要的控件,其可以展示比設(shè)備屏幕更大區(qū)域的內(nèi)容,我們可以通過手指滑動來查看內(nèi)容視圖的每一部分內(nèi)容,也可以通過手指捏合來對內(nèi)容視圖進行縮放操作,我們每天開發(fā)中都不斷顯式或隱式地與UIScrollView打交道,下面給大家詳細介紹UIScrollView控件。
    2016-09-09
  • 總結(jié)iOS開發(fā)中的斷點續(xù)傳與實踐

    總結(jié)iOS開發(fā)中的斷點續(xù)傳與實踐

    本文先從斷點續(xù)傳問題開始,介紹斷點續(xù)傳概述和原理。接著結(jié)合筆者調(diào)研中嘗試的 AFHTTPRequestOpeartion,簡單分析源碼。最后分別基于 NSURLConnection,NSURLSessionDataTask 和 NSURLSessionDownloadTask 去實現(xiàn)應(yīng)用重啟情況下的斷點續(xù)傳。下面一起來看看。
    2016-07-07
  • iOS中 UIImage根據(jù)屏寬調(diào)整size的實例代碼

    iOS中 UIImage根據(jù)屏寬調(diào)整size的實例代碼

    最近做項目遇到這樣一個需求,要求UIImage根據(jù)屏幕寬度按照自己本身比例改變高度,下面通過本文給大家分享iOS UIImage根據(jù)屏寬調(diào)整size的實例代碼,需要的朋友參考下吧
    2017-01-01

最新評論