首先呢
UIAlertController是presentViewController 屬於模型跳轉 模型是vc才可以present 所以把添加在window上面的view賦值個vc 在vc上面進去present
AppDelegate *delegate =(id)[UIApplication sharedApplication].delegate;
UIViewController *vc = [[UIViewController alloc] init];//實例化一個vc
vc.view = self.typeView;//self.typeView這個是添加在window上面的view
[delegate.window addSubview:vc.view];//添加
/* 彈出相冊 */
WS(weakself);
_typeView.block = ^{
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *_Nonnull action) {
}];
UIAlertAction *camera = [UIAlertAction actionWithTitle:@"打開相機" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[weakself takePhoto];
}];
UIAlertAction *picture = [UIAlertAction actionWithTitle:@"打開相冊" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[weakself localPhoto];
}];
[alertVc addAction:cancle];
[alertVc addAction:camera];
[alertVc addAction:picture];
[vc presentViewController:alertVc animated:YES completion:nil];
};