1

在此处输入图像描述

我正在尝试复制中间的屏幕,即为撰写新推文而显示的警报。我试图用自定义来复制它,UIAlertView但这需要大量的子类化而不是什么,然后我怀疑它可能只是一个UIViewController显示在主视图上的简单......需要来自 iOS 开发人员的专业想法。

谢谢你。

4

1 回答 1

1

在 iPad 中:

您可以使用UIViewController来完成。

  • 您需要根据上图设计 UI。
  • 然后您需要将模态演示样式设置为UIModalPresentationFormSheet
  • 并使用- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))

像:

UIViewController *viewC = [[UIViewController alloc] init];
viewC.view.frame = //set the frame;
viewC.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:viewC animated:YES completion:nil];

在 iPhone 中:

您可以使用UIView来做到这一点。

您可以使用以下代码执行此操作:

在你的界面中声明一个属性

@property (nonatomic, strong) UIView *views;

//添加视图

- (void) showView
{
   UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 35)];
        UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(remove)];
        toolbar.items = [NSArray arrayWithObject:bar];
        _views = [[UIView alloc] initWithFrame:CGRectMake(0, -300, self.view.bounds.size.width, self.view.bounds.size.height/3)];
        [_views addSubview:toolbar];
        [_views setBackgroundColor:[UIColor grayColor]];
        [self.view addSubview:_views];
        [UIView animateWithDuration:0.7
                              delay:0.0
                            options:UIViewAnimationCurveLinear
                         animations:^{

                             _views.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height/3);
                         }
                         completion:^(BOOL yes){
                             NSLog(@"YO");

                         }];
        [UIView commitAnimations];
}

//移除视图

- (void)remove
{
    [UIView animateWithDuration:0.7
                          delay:0.0
                        options:UIViewAnimationCurveLinear
                     animations:^{
                         _views.frame = CGRectMake(0, -500, self.view.bounds.size.width, self.view.bounds.size.height/3);
                     }
                     completion:^(BOOL yes){
                         NSLog(@"YA");

                     }];
    [UIView commitAnimations];
}
于 2013-07-03T09:42:56.723 回答