欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IOS實現(xiàn)點擊滑動抽屜效果

 更新時間:2016年02月27日 10:09:32   投稿:lijiao  
這篇文章主要為大家詳細介紹了IOS實現(xiàn)點擊滑動抽屜效果的相關資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

最近,看到好多Android上的抽屜效果,也忍不住想要自己寫一個。在Android里面可以用SlidingDrawer,很方便的實現(xiàn)。IOS上面就只有自己寫了。其實原理很簡單就是 UIView 的移動,和一些手勢的操作。

效果圖:

// 
// DrawerView.h 
// DrawerDemo 
// 
// Created by Zhouhaifeng on 12-3-27. 
// Copyright (c) 2012年 CJLU. All rights reserved. 
// 
 
#import <UIKit/UIKit.h> 
 
typedef enum 
{ 
 DrawerViewStateUp = 0, 
 DrawerViewStateDown 
}DrawerViewState; 
 
@interface DrawerView : UIView<UIGestureRecognizerDelegate> 
{ 
 UIImageView *arrow;   //向上拖拽時顯示的圖片  
 
 CGPoint upPoint;   //抽屜拉出時的中心點 
 CGPoint downPoint;   //抽屜收縮時的中心點 
  
 UIView *parentView;   //抽屜所在的view 
 UIView *contentView;  //抽屜里面顯示的內容 
  
 DrawerViewState drawState; //當前抽屜狀態(tài) 
} 
 
- (id)initWithView:(UIView *) contentview parentView :(UIView *) parentview; 
- (void)handlePan:(UIPanGestureRecognizer *)recognizer; 
- (void)handleTap:(UITapGestureRecognizer *)recognizer; 
- (void)transformArrow:(DrawerViewState) state; 
 
@property (nonatomic,retain) UIView *parentView; 
@property (nonatomic,retain) UIView *contentView; 
@property (nonatomic,retain) UIImageView *arrow; 
@property (nonatomic) DrawerViewState drawState; 
 
@end 
// 
// DrawerView.m 
// DrawerDemo 
// 
// Created by Zhouhaifeng on 12-3-27. 
// Copyright (c) 2012年 CJLU. All rights reserved. 
// 
 
#import "DrawerView.h" 
 
@implementation DrawerView 
@synthesize contentView,parentView,drawState; 
@synthesize arrow; 
 
- (id)initWithView:(UIView *) contentview parentView :(UIView *) parentview; 
{ 
 self = [super initWithFrame:CGRectMake(0,0,contentview.frame.size.width, contentview.frame.size.height+40)]; 
 if (self) { 
  // Initialization code   
  contentView = contentview; 
  parentView = parentview; 
   
  //一定要開啟 
  [parentView setUserInteractionEnabled:YES]; 
   
  //嵌入內容區(qū)域的背景 
  UIImage *drawer_bg = [UIImage imageNamed:@"drawer_content.png"]; 
  UIImageView *view_bg = [[UIImageView alloc]initWithImage:drawer_bg]; 
  [view_bg setFrame:CGRectMake(0,40,contentview.frame.size.width, contentview.bounds.size.height+40)]; 
  [self addSubview:view_bg]; 
  
  //頭部拉拽的區(qū)域背景 
  UIImage *drawer_handle = [UIImage imageNamed:@"drawer_handlepng.png"]; 
  UIImageView *view_handle = [[UIImageView alloc]initWithImage:drawer_handle]; 
  [view_handle setFrame:CGRectMake(0,0,contentview.frame.size.width,40)]; 
  [self addSubview:view_handle]; 
   
  //箭頭的圖片 
  UIImage *drawer_arrow = [UIImage imageNamed:@"drawer_arrow.png"]; 
  arrow = [[UIImageView alloc]initWithImage:drawer_arrow]; 
  [arrow setFrame:CGRectMake(0,0,28,28)]; 
  arrow.center = CGPointMake(contentview.frame.size.width/2, 20); 
  [self addSubview:arrow]; 
   
  //嵌入內容的UIView 
  [contentView setFrame:CGRectMake(0,40,contentview.frame.size.width, contentview.bounds.size.height+40)]; 
  [self addSubview:contentview]; 
   
  //移動的手勢 
  UIPanGestureRecognizer *panRcognize=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; 
  panRcognize.delegate=self; 
  [panRcognize setEnabled:YES]; 
  [panRcognize delaysTouchesEnded]; 
  [panRcognize cancelsTouchesInView]; 
   
  [self addGestureRecognizer:panRcognize]; 
   
  //單擊的手勢 
  UITapGestureRecognizer *tapRecognize = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)]; 
  tapRecognize.numberOfTapsRequired = 1; 
  tapRecognize.delegate = self; 
  [tapRecognize setEnabled :YES]; 
  [tapRecognize delaysTouchesBegan]; 
  [tapRecognize cancelsTouchesInView]; 
   
  [self addGestureRecognizer:tapRecognize]; 
   
  //設置兩個位置的坐標 
  downPoint = CGPointMake(parentview.frame.size.width/2, parentview.frame.size.height+contentview.frame.size.height/2-40); 
  upPoint = CGPointMake(parentview.frame.size.width/2, parentview.frame.size.height-contentview.frame.size.height/2-40); 
  self.center = downPoint; 
   
  //設置起始狀態(tài) 
  drawState = DrawerViewStateDown; 
 } 
 return self; 
} 
 
 
#pragma UIGestureRecognizer Handles 
/*  
 * 移動圖片處理的函數(shù) 
 * @recognizer 移動手勢 
 */ 
- (void)handlePan:(UIPanGestureRecognizer *)recognizer { 
  
  
 CGPoint translation = [recognizer translationInView:parentView]; 
 if (self.center.y + translation.y < upPoint.y) { 
  self.center = upPoint; 
 }else if(self.center.y + translation.y > downPoint.y) 
 { 
  self.center = downPoint; 
 }else{ 
  self.center = CGPointMake(self.center.x,self.center.y + translation.y); 
 } 
 [recognizer setTranslation:CGPointMake(0, 0) inView:parentView]; 
  
 if (recognizer.state == UIGestureRecognizerStateEnded) { 
  [UIView animateWithDuration:0.75 delay:0.15 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
    if (self.center.y < downPoint.y*4/5) { 
     self.center = upPoint; 
     [self transformArrow:DrawerViewStateUp]; 
    }else 
    { 
     self.center = downPoint; 
     [self transformArrow:DrawerViewStateDown]; 
    } 
 
  } completion:nil]; 
 
 }  
} 
 
/* 
 * handleTap 觸摸函數(shù) 
 * @recognizer UITapGestureRecognizer 觸摸識別器 
 */ 
-(void) handleTap:(UITapGestureRecognizer *)recognizer 
{ 
  [UIView animateWithDuration:0.75 delay:0.15 options:UIViewAnimationOptionTransitionCurlUp animations:^{ 
   if (drawState == DrawerViewStateDown) { 
    self.center = upPoint; 
    [self transformArrow:DrawerViewStateUp]; 
   }else 
   { 
    self.center = downPoint; 
    [self transformArrow:DrawerViewStateDown]; 
   } 
  } completion:nil]; 
 
} 
 
/* 
 * transformArrow 改變箭頭方向 
 * state DrawerViewState 抽屜當前狀態(tài) 
 */ 
-(void)transformArrow:(DrawerViewState) state 
{ 
  //NSLog(@"DRAWERSTATE :%d STATE:%d",drawState,state); 
  [UIView animateWithDuration:0.3 delay:0.35 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
   if (state == DrawerViewStateUp){  
     arrow.transform = CGAffineTransformMakeRotation(M_PI); 
    }else 
    { 
      arrow.transform = CGAffineTransformMakeRotation(0); 
    } 
  } completion:^(BOOL finish){ 
    drawState = state; 
  }]; 
   
  
} 
 
@end 

以上就是本文的全部內容,希望對大家的學習有所幫助。

相關文章

  • 淺談Unity中IOS Build Settings選項的作用

    淺談Unity中IOS Build Settings選項的作用

    下面小編就為大家分享一篇淺談Unity中IOS Build Settings選項的作用,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • 在iOS應用中使用UIWebView創(chuàng)建簡單的網頁瀏覽器界面

    在iOS應用中使用UIWebView創(chuàng)建簡單的網頁瀏覽器界面

    這篇文章主要介紹了在iOS應用中使用UIWebView創(chuàng)建簡單的網頁瀏覽器界面的方法,包括動態(tài)獲取UIWebView高度的實現(xiàn),需要的朋友可以參考下
    2016-01-01
  • 快速解決iOS10不能跳轉系統(tǒng)WiFi列表的問題

    快速解決iOS10不能跳轉系統(tǒng)WiFi列表的問題

    下面小編就為大家?guī)硪黄焖俳鉀QiOS10不能跳轉系統(tǒng)WiFi列表的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • iOS9開放的新API--Spotlight使用指南

    iOS9開放的新API--Spotlight使用指南

    作為蘋果iOS9的重要特性之一,Spotlight搜索如今重新回到主界面最左側(同樣支持主界面下滑呼出),通過API的支持,還帶來了全新的Universal Search通用搜索功能,除了網絡以及系統(tǒng)本身內容之外,還能直接搜索第三方應用內的相關內容。下面我們就來詳細研究下Spotlight
    2015-11-11
  • iOS如何獲取最頂層ViewController詳解

    iOS如何獲取最頂層ViewController詳解

    這篇文章主要給大家介紹了關于iOS如何獲取最頂層ViewController的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-09-09
  • iOS10語音識別框架SpeechFramework應用詳解

    iOS10語音識別框架SpeechFramework應用詳解

    在iOS10系統(tǒng)了,apple開放了與語音識別相關的接口,開發(fā)者可以將其應用到自己的App中,實現(xiàn)用戶通過語音進行功能操作。 這篇文章主要介紹了iOS10語音識別框架SpeechFramework應用,需要的朋友可以參考下
    2016-09-09
  • IOS 常見的循環(huán)引用總結

    IOS 常見的循環(huán)引用總結

    這篇文章主要介紹了IOS 常見的循環(huán)引用總結的相關資料,循環(huán)引用,指的是多個對象相互引用時,使得引用形成一個環(huán)形,導致外部無法真正是否掉這塊環(huán)形內存。其實有點類似死鎖,需要的朋友可以參考下
    2017-03-03
  • iOS開發(fā)之topLayoutGuide和bottomLayoutGuide的使用小技巧分享

    iOS開發(fā)之topLayoutGuide和bottomLayoutGuide的使用小技巧分享

    這篇文章主要給大家介紹了關于iOS開發(fā)之topLayoutGuide和bottomLayoutGuide使用的一些小技巧,需要的朋友可以參考下
    2017-11-11
  • iOS中的ipa重簽名(逆向必備)

    iOS中的ipa重簽名(逆向必備)

    這篇文章給大家介紹了ios中的ipa重簽名知識以及錯誤原因及解決俄方案,需要的朋友參考下吧
    2018-01-01
  • 解決ios h5 input輸入框被輸入法彈出一塊區(qū)域的問題

    解決ios h5 input輸入框被輸入法彈出一塊區(qū)域的問題

    今天小編就為大家分享一篇解決ios h5 input輸入框被輸入法彈出一塊區(qū)域的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08

最新評論