gpt4 book ai didi

ios - 如何在ipad应用程序的后台线程中显示UIAlertView?

转载 作者:行者123 更新时间:2023-11-29 03:48:54 26 4
gpt4 key购买 nike

当某些代码在后台执行时,我需要显示警报 View 。为此,我实现了以下代码。

//this is loading alert  
-(void)showAlert:(NSString *)message {

// UIAlertView *alert;
alert11 = [[UIAlertView alloc] initWithTitle:@"Updates" message:message delegate:self
cancelButtonTitle:@"OK" otherButtonTitles: nil];
#ifndef IOS5_1
[alert11 autorelease];
#endif

[alert11 show];

}

-(void) showUpdates1:(NSString *)data {
isUpdating = true;
VideoBrowserAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate initApplicationDefaults];
[self performSelectorOnMainThread:@selector(showAlert:)
withObject:@"Please wait while Updating the view...."
waitUntilDone:YES];
[appDelegate openExhibitView1];
//this is update completed alert
[VideoBrowserAppDelegate addUpdateLog:@"Update is completed" showLog:TRUE calledFrom:nil];

}

但是当执行performSelectorOnMainThread(..)时,会显示警报,但第二秒就消失了。之后,openExhibitView1() 完全执行,并再次更新正确显示的警报。当我们再次单击更新警报的“确定”按钮时,将显示加载警报。但这不公平。我需要显示加载警报,直到 openExhibitView1() 在后台执行,除非我们单击“确定”按钮。

最佳答案

我建议你编写自己的AlertView。但请不要忘记,iOS 上禁止对alertView 进行子类化。

我建议你创建自己的 UIView 子类并实现 showWithMessage、title 等方法。组合 View 然后显示它。

此外,如果您坚持使用警报..这里有一篇有趣的文章可能会有所帮助...

Multithreading iOS - performing alerts

但我的建议是使用自定义显示动画对 UIView 进行子类化。动画示例:

  - (void)animateShow
{
CAKeyframeAnimation *animation = [CAKeyframeAnimation
animationWithKeyPath:@"transform"];

CATransform3D scale1 = CATransform3DMakeScale(0.5, 0.5, 1);
CATransform3D scale2 = CATransform3DMakeScale(1.2, 1.2, 1);
CATransform3D scale3 = CATransform3DMakeScale(0.9, 0.9, 1);
CATransform3D scale4 = CATransform3DMakeScale(1.0, 1.0, 1);

NSArray *frameValues = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:scale1],
[NSValue valueWithCATransform3D:scale2],
[NSValue valueWithCATransform3D:scale3],
[NSValue valueWithCATransform3D:scale4],
nil];
[animation setValues:frameValues];

NSArray *frameTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:0.9],
[NSNumber numberWithFloat:1.0],
nil];
[animation setKeyTimes:frameTimes];

animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.duration = 0.2;

[self.layer addAnimation:animation forKey:@"show"];
}

- (void)animateHide
{
CAKeyframeAnimation *animation = [CAKeyframeAnimation
animationWithKeyPath:@"transform"];

CATransform3D scale1 = CATransform3DMakeScale(1.0, 1.0, 1);
CATransform3D scale2 = CATransform3DMakeScale(0.5, 0.5, 1);
CATransform3D scale3 = CATransform3DMakeScale(0.0, 0.0, 1);

NSArray *frameValues = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:scale1],
[NSValue valueWithCATransform3D:scale2],
[NSValue valueWithCATransform3D:scale3],
nil];
[animation setValues:frameValues];

NSArray *frameTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:0.9],
nil];
[animation setKeyTimes:frameTimes];

animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.duration = 0.1;

[self.layer addAnimation:animation forKey:@"hide"];

[self performSelector:@selector(removeFromSuperview) withObject:self afterDelay:0.105];
}

关于ios - 如何在ipad应用程序的后台线程中显示UIAlertView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17319411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com