最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

前言

iOS中抽屜效果的簡(jiǎn)單實(shí)現(xiàn)現(xiàn)在很多應(yīng)用中都使用到了,網(wǎng)上也有很多了例子,本文主要是通過(guò)簡(jiǎn)單的一些代碼來(lái)實(shí)現(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];
  // 給左視圖和主視圖添加手勢(shì)
  [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;
  }
}
// 給左視圖和主視圖添加手勢(shì)
- (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];
}
// 平移和縮放一個(gè)視圖
- (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é)

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

相關(guān)文章

最新評(píng)論

哈巴河县| 西乌珠穆沁旗| 射洪县| 宁安市| 怀宁县| 建宁县| 定安县| 明水县| 兴宁市| 会宁县| 平阳县| 建始县| 桓台县| 棋牌| 叙永县| 沭阳县| 商城县| 蒲江县| 临澧县| 遵化市| 施秉县| 三门县| 凌海市| 长汀县| 霞浦县| 屏山县| 开原市| 伊金霍洛旗| 绥宁县| 天等县| 余干县| 高唐县| 长垣县| 兴安县| 景东| 泽州县| 余干县| 高安市| 民丰县| 德兴市| 攀枝花市|