HFUTAlertController
HFUTAlertController是一個(gè)基于轉(zhuǎn)場(chǎng)動(dòng)畫(huà),封裝了一些類(lèi)似于UIAlertController的一些操作棘伴。
項(xiàng)目地址
說(shuō)明
展示
使用的三方庫(kù)
pop:facebook開(kāi)源的游戲級(jí)別的動(dòng)畫(huà)引擎乐尊,相當(dāng)好用樊诺,點(diǎn)擊鏈接了解詳情
Masonry:封裝的非常好用的布局操作咬最,相當(dāng)方便邮辽,點(diǎn)擊鏈接了解詳情
使用
開(kāi)始
首先需要導(dǎo)入上面所說(shuō)的三方庫(kù)蕴轨,然后直接下載文件導(dǎo)入項(xiàng)目
接著包含頭文件
#import "HFUTAlert.h"
假設(shè)在一個(gè)ViewController
上彈出AlertController
港谊,需要ViewController
遵從<UIViewControllerTransitioningDelegate>
協(xié)議,并實(shí)現(xiàn)下面兩個(gè)方法橙弱。
//ViewController.m
@interface ViewController () <UIViewControllerTransitioningDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// Do any additional setup after loading the view.
}
#pragma mark - UIViewControllerTransitioningDelegate
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
return [HFUTPresentingAnimator new];
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
return [HFUTDismissingAnimator new];
}
@end
假設(shè)點(diǎn)擊一個(gè)ViewController
里的按鈕彈出Alert
- (IBAction)button:(id)sender {
HFUTAlertController * alert = [HFUTAlertController alertWithTitle:@"XXOO" message:@"xxxxxoooooo" style:AlertStyleInfoWithDoubleButton];
alert.transitioningDelegate = self; //F缢隆!棘脐!一定要有
[self presentViewController:alert animated:YES completion:nil];
}
如果ViewController
繼承NavigationController斜筐,就使用這個(gè)方法彈出
[self.navigationController presentViewController:alert animated:YES completion:nil];
操作
設(shè)置確認(rèn)和取消按鈕的響應(yīng)事件,在presentViewController
之前通過(guò)下面操作
[alert setDefaultCompletion:^{
...
}];
[alert setCancelCompletion:^{
...
}]
更改按鈕的名字
[alert setDefaultButtonTitle:title];
[alert setCancelButtonTitle:title];
了解
選擇不一樣的style又不一樣風(fēng)格的Alert
- AlertStyleDefaultWithSingleButton
- AlertStyleDefaultWithDoubleButton
- AlertStyleSuccessWithSingleButton
- AlertStyleFailureWithSingleButton
- AlertStyleInfoWithSingleButton