view添加在window上面 在view上彈出UIAlertController


首先呢

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];

    };


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM