ios - UIAlertView subview 定位

标签 ios cocoa-touch ipad uiview uialertview

我有一个 alertView,它会在用户更改标签页时弹出

UIAlertView *tempAlert = [[UIAlertView alloc] initWithTitle:@"Save Video?" 
                                                    message:@"Do you wish to save the video ?" 
                                                   delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"Save",nil];
[tempAlert show];
[tempAlert setDelegate:self];
self.saveAlert = tempAlert;
[tempAlert release];

现在我处理按钮单击事件,在这个事件中我想显示另一个带有 progressView 作为 subview 的警报

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{
if ([alertView.title isEqualToString:@"Save Video?"])
{
    if (buttonIndex == [alertView cancelButtonIndex]) 
    {
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; //17.4.12
        // Adjust the indicator so it is up a few pixels from the bottom of the alert
        indicator.center = CGPointMake(self.saveAlert.bounds.size.width / 2, self.saveAlert.bounds.size.height - 40);
        [indicator startAnimating];
        [self.saveAlert addSubview:indicator];
        [indicator release];
        [(ImageCanvas1AppDelegate*)[[UIApplication sharedApplication] delegate] setMainAlert:self.saveAlert];


        [NSThread detachNewThreadSelector:@selector(performSaveOperationWithTabChangeToIndex:) toTarget:self withObject:[NSNumber numberWithInt:self.tab]];
    }
    else
    {
        [self performSelectorOnMainThread:@selector(playMovie)
                               withObject:nil waitUntilDone:YES];
    }
}
else
{
    if (buttonIndex == [alertView cancelButtonIndex]) 
    {
        [self.videoGenerator cancelVideoGeneration];
    }
}
}

如果用户确实触摸了保存按钮,我会显示一个带有 progressView 作为 subview 的 alertView 此方法在“playMovie”方法中调用

- (void)showAlert
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Generating Video" 
                                                message:@"Please wait!" 
                                               delegate:self cancelButtonTitle:@"Cancel" 
                                      otherButtonTitles:nil, nil];

[alert performSelectorOnMainThread:@selector(show)
                        withObject:nil
                     waitUntilDone:YES];
[alert setDelegate:self];
self.videoAlert = alert;
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
[progressView setFrame:CGRectMake(alert.bounds.size.width - progressView.bounds.size.width - 95,
                                  alert.bounds.size.height - progressView.bounds.size.height - 80, 
                                  progressView.bounds.size.width, 
                                  progressView.bounds.size.height)];
[alert addSubview:progressView];
self.progressView = progressView;
[progressView release];

[alert release];

[pool release];
}

问题是:

如果我正常显示 alertView,则 subview 定位没问题

但是如果我在

中显示 alertView

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

progressView的位置不对

最佳答案

为什么要在 uialertview 中显示进度? UIalertviews 是模态的。创建您自己的 View 并显示,您可以完全控制这种方式,您可以添加暂停、继续和停止按钮,您可以显示您想要的所有信息。

关于ios - UIAlertView subview 定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10681156/

相关文章:

ios - 我可以更新协议(protocol)扩展中的指定属性吗?

ios - UIScrollView 中的水平缩放

ios - longPress 时启用 UIPanGestureRecognizer

ios - UITextView contentOffset 在 vi​​ewDidLoad 和 viewDidAppear 之间变化

ios - 从日历组件创建 NSDate 时出现 1 错误

iphone - 注册推送通知

objective-c - iOS 相机 UIView 在 iPad 上覆盖全屏?

objective-c - 如何在输入 View 移动时使 VoiceOver 工作

ios - 更改 iOS 窗口的 Root View Controller

iPhone 4 和 iPad 2 : Advantages of fixed point arithmetic over floating point