【问题标题】:UIView as AlertViewUIView 作为 AlertView
【发布时间】:2012-11-05 08:16:39
【问题描述】:

我正在处理一个项目,我必须显示类似于 的自定义警报视图

我发现,自定义 UIAlertView 是一种错误的方法!所以实现它的方法是使用 UIView,它会像 UIAlertView 一样使用动画弹出和弹出。

我还看到了一些 SO [问题]:How can I customize an iOS alert view? 和 [问题]:UIView Popup like UIAlertView 我仍然面临问题,例如 AlertView 没有出现。任何人都可以分享一些相同的好教程。

//谢谢

【问题讨论】:

  • 自定义警报视图并实现它的drawRect方法。

标签: ios xcode


【解决方案1】:

系统UIAlertView 会创建自己的UIWindow,因此它可以浮动在您的正常UIWindow 之上。您可能想尝试这种方法。如果你这样做了,你可能会在this answer about using extra UIWindows 中找到一些有用的提示。

【讨论】:

  • 我继承了 UIView 类来绘制这个菜单。然后实例化它以显示在父视图控制器上。为了处理父 VC 中的触摸事件,我使用了协议委托方法!
【解决方案2】:

您可以使用模态视图控制器

模态视图控制器只是一个以模态形式呈现的 UIViewController 类。

要以模态方式呈现视图控制器,您可以使用以下方法:

- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;

将 Frame 更改为 50% 的视图,您可以对其应用不同的动画以进行表示。

这里是可用的模态过渡样式

yourModelViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
yourModelViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
yourModelViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
yourModelViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;

示例代码:

UIViewController *controller = [[MyViewController alloc] init];
controller.frame = yourFrame;
UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition: trans forView: [self window] cache: YES];
[self.view presentModalViewController: controller animated: NO];
[UIView commitAnimations];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-02
    • 2017-07-26
    • 1970-01-01
    相关资源
    最近更新 更多