这几天忙的如🐶,因为习惯了冬天的冷,中午休息小憩一会 ,但是还是有点不是很过瘾,还是周末给力,一觉睡到自然醒,忽然间看到公司微信群老大提的 bug 出现在眼前,心情顿时不好了,老大,这可是周末,是没有工资的 freetime, i want to be a free man!!!
    今天首要任务就是 fix bug, 砍了几个但是还是有些问题,明天继续, ono, 今天已经是明天了.洗洗睡了,😴 都是瞎扯一通,莫怪干货在下面,可劲造~

    先上图
    OC(十六)-自定义-actionsheet - 图1

    OC(十六)-自定义-actionsheet - 图2

    . h

    1. //
    2. // ShowNumOfSeletedPics.h
    3. // FileTransfer
    4. //
    5. // Created by HMC on 16/9/6.
    6. // Copyright © 2016年 SKing. All rights reserved.
    7. //
    8. #import <UIKit/UIKit.h>
    9. @interface ShowMenuOfBigPics : UIView
    10. @property (copy, nonatomic) void (^btnClickedBlock)(NSInteger index);
    11. //-(instancetype)initWithFrame:(CGRect)frame array:(NSArray * )btnTitleArray;
    12. /** 自定义初始化函数
    13. @param frame 大小
    14. @param cancelButtonTitle 取消按钮 不可空
    15. @param otherButtonTitles 操作类按钮
    16. @return self
    17. */
    18. - (instancetype)initWithFrame:(CGRect)frame cancelButtonTitle:(nonnull NSString *)cancelButtonTitle otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
    19. -(void)showInSuperView:(UIView *)view;
    20. -(void)hide;
    21. @end

    .m

    1. //
    2. // ShowNumOfSeletedPics.m
    3. // FileTransfer
    4. //
    5. // Created by HMC on 16/9/6.
    6. // Copyright © 2016年 SKing. All rights reserved.
    7. //
    8. #define heightOfBtn
    9. #import "ShowMenuOfBigPics.h"
    10. @interface ShowMenuOfBigPics()
    11. //view 的背景
    12. @property (strong, nonatomic) UIView * bgView;
    13. //按钮的背景
    14. @property (strong, nonatomic) UIView * btnBGView;
    15. @property (assign, nonatomic) NSInteger arrayCount;
    16. @end
    17. @implementation ShowMenuOfBigPics
    18. -(instancetype)initWithFrame:(CGRect)frame cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION{
    19. NSMutableArray * arrayTitle = [NSMutableArray array];
    20. //指向参数的指针变量
    21. va_list btnTitle;
    22. //初始化上面的变量 otherButtonTitles 是可选参数的第一个参数
    23. va_start(btnTitle, otherButtonTitles);
    24. if(otherButtonTitles){
    25. //第一个直接放进数组
    26. [arrayTitle addObject:otherButtonTitles];
    27. //循环遍历放入数组
    28. //返回下一个参数,nsstring 为类型, 并指向下一个参数
    29. while ((otherButtonTitles = va_arg(btnTitle, NSString *))) {
    30. [arrayTitle addObject:otherButtonTitles];
    31. }
    32. }
    33. NSLog(@"%@",arrayTitle) ;
    34. //释放指针变量
    35. va_end(btnTitle);
    36. if (self = [super initWithFrame:frame]) {
    37. _arrayCount = arrayTitle.count;
    38. [self addSubview:self.bgView];
    39. //按钮的背景
    40. _btnBGView = [[UIView alloc]initWithFrame:(CGRect){0,HEIGHTOFSCREEN ,WIDTHOFSCREEN,(arrayTitle.count + 1 ) * 50 + 5 }];
    41. _btnBGView.backgroundColor = setRGBColor(233, 233, 233, 1.0);
    42. [self addSubview:_btnBGView];
    43. //创建按钮组
    44. for (int i = 0 ;i <= arrayTitle.count ; i++) {
    45. UIButton * btn = [[UIButton alloc]initWithFrame:(CGRect){0, 50.5 * i,WIDTHOFSCREEN,50}];
    46. btn.backgroundColor = [UIColor whiteColor];
    47. btn.tag = i ;
    48. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    49. [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    50. if (i != arrayTitle.count) {
    51. [btn setTitle:arrayTitle[i] forState:UIControlStateNormal];
    52. }else{
    53. btn.frame = (CGRect){0, 50.5 * i + 5,WIDTHOFSCREEN,50};
    54. [btn setTitle:cancelButtonTitle forState:UIControlStateNormal];
    55. }
    56. [_btnBGView addSubview:btn];
    57. }
    58. }
    59. return self;
    60. }
    61. -(UIView *)bgView{
    62. if (!_bgView) {
    63. //_bgView添加手势
    64. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
    65. _bgView = [[UIView alloc]initWithFrame:(CGRect){0,0,WIDTHOFSCREEN,HEIGHTOFSCREEN - 55}];
    66. _bgView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    67. [_bgView addGestureRecognizer:tap];
    68. }
    69. return _bgView;
    70. }
    71. -(void)btnClicked:(UIButton *)btn {
    72. NSLog(@"点击了按钮");
    73. //[self hide];
    74. self.btnClickedBlock(btn.tag);
    75. }
    76. -(void)layoutSubviews{
    77. [super layoutSubviews];
    78. }
    79. -(void)showInSuperView:(UIView *)view{
    80. [view addSubview:self];
    81. [UIView animateWithDuration:0.5 animations:^{
    82. self.btnBGView.frame = (CGRect){0,HEIGHTOFSCREEN - (self.arrayCount + 1 ) * 50 - 5,WIDTHOFSCREEN,(self.arrayCount + 1 ) * 50 + 5 };
    83. } completion:^(BOOL finished) {
    84. }];
    85. }
    86. -(void)hide{
    87. self.bgView.hidden = YES;
    88. [UIView animateWithDuration:1.0 animations:^{
    89. self.frame = (CGRect){0,HEIGHTOFSCREEN ,WIDTHOFSCREEN ,0};
    90. } completion:^(BOOL finished) {
    91. [self removeFromSuperview];
    92. }];
    93. }
    94. @end

    调用

    1. ShowMenuOfBigPics * menuView = [[ShowMenuOfBigPics alloc] initWithFrame:(CGRect){0,0,WIDTHOFSCREEN,HEIGHTOFSCREEN} cancelButtonTitle:@"取消" otherButtonTitles:@"保存图片",nil];
    2. [menuView showInSuperView:self.view];
    3. weaklySelf(menuView);
    4. menuView.btnClickedBlock = ^(NSInteger index){
    5. switch (index) {
    6. case 0:
    7. NSLog(@"保存图片");
    8. [self savePicToLib:self.currentImage];
    9. break;
    10. case 1:
    11. {
    12. NSLog(@"取消");
    13. }
    14. break;
    15. default:
    16. break;
    17. }
    18. [weakSelf hide];
    19. };