日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS基础:ActionSheet(上拉菜单)的实现

發布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS基础:ActionSheet(上拉菜单)的实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


一看圖就明白了,毋需多說。

?

[java] view plaincopyprint?
  • UIActionSheet*?mySheet?=?[[UIActionSheet?alloc]??
  • ???????????????????????????initWithTitle:@"ActionChoose"???
  • ???????????????????????????delegate:self???
  • ???????????????????????????cancelButtonTitle:@"Cancel"??
  • ???????????????????????????destructiveButtonTitle:@"Destroy"??
  • ???????????????????????????otherButtonTitles:@"OK",?nil];??
  • ????[mySheet?showInView:self.view];??
  • 與UIAlertView類似,我們也是在委托方法里處理按下按鈕后的動作。記得在所委托的類加上UIActionSheetDelegate。

    ?

    [java] view plaincopyprint?
  • -?(void)actionSheetCancel:(UIActionSheet?*)actionSheet{??
  • ????// ??
  • }??
  • -?(void)?actionSheet:(UIActionSheet?*)actionSheet?clickedButtonAtIndex:(NSInteger)buttonIndex{??
  • ????// ??
  • }??
  • -(void)actionSheet:(UIActionSheet?*)actionSheet?didDismissWithButtonIndex:(NSInteger)buttonIndex{??
  • ????// ??
  • }??
  • -(void)actionSheet:(UIActionSheet?*)actionSheet?willDismissWithButtonIndex:(NSInteger)buttonIndex{??
  • ????// ??
  • }??
  • 看到那個紅色的按鈕沒?那是ActionSheet支持的一種所謂的銷毀按鈕,對某戶的某個動作起到警示作用,

    比如永久性刪除一條消息或者日志。如果你指定了一個銷毀按鈕他就會以紅色高亮顯示:

    ?

    [java] view plaincopyprint?
  • mySheet.destructiveButtonIndex=1;??
  • 與導航欄類似,操作表單也支持三種風格 :

    ?

    ?

    [java] view plaincopyprint?
  • UIActionSheetStyleDefault??????????????//默認風格:灰色背景上顯示白色文字 ??
  • UIActionSheetStyleBlackTranslucent?????//透明黑色背景,白色文字 ??
  • UIActionSheetStyleBlackOpaque??????????//純黑背景,白色文字??
  • 用法用例:

    ?

    mySheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;

    顯示ActionSheet有三種方法:

    1.在一個視圖內部顯示,可以用showInView

    [mySheet showInView:self];

    2.如果要將ActonSheet 與工具欄或者標簽欄對齊,可以使用showFromToolBar或showFromTabBar

    [mySheet showFromToolBar:toolbar];

    [mySheet showFromTabBar:tabbar];
    解除操作表單

    用戶按下按鈕之后,Actionsheet就會消失——除非應用程序有特殊原因,需要用戶按下做個按鈕。用dismiss方法可令表單消失:

    ?

    [java] view plaincopyprint?
  • [mySheet?dismissWithClickButtonIndex:1?animated:YES];??

  • ?

    必須使用Protocol,在類定義的地方定義使用UIActionSheetDelegate協議,

    @interface?XXXController : UIViewController <UIActionSheetDelegate> {...

    ?

    在程序里面調用

    UIActionSheet *actionSheet = [[UIActionSheet alloc]

    ? initWithTitle:@"Are you sure?" ? ? ? ? //標題

    ??delegate:self ? ? ? ? ? ? ? ? ?//此處指定處理按鈕按下之后的事件的類,該類必須實現UIActionSheetDelegate協議

    ? cancelButtonTitle:@"Cancel"?

    ? destructiveButtonTitle:@"OK"

    ? otherButtonTitles:@"button1", @"button2", nil]; ?//可指定很多個button,最后一個參數必須為nil,此為OBJC特殊特性

    [actionSheet showInView:self.view]; ? //在哪個view里面彈出上拉菜單

    [actionSheet release]; ? ?//一定要release

    記得最后一定要release!

    ?

    處理按鈕事件的方法為實現UIActionSheetDelegate協議的actionSheet方法:

    - (void)actionSheet:(UIActionSheet *)actionSheet

    didDismissWithButtonIndex:(NSInteger)buttonIndex

    {

    ?? ?if( buttonIndex != [actionSheet cancelButtonIndex]){

    ?? ? ? ?//...

    ?? ?}

    }

    轉載于:https://www.cnblogs.com/martin1009/archive/2012/06/25/2561362.html

    總結

    以上是生活随笔為你收集整理的IOS基础:ActionSheet(上拉菜单)的实现的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。