gpt4 book ai didi

objective-c - XCode 自定义事件指示器 - 在 UIWebView 加载后隐藏 (webViewDidFinishLoad)

转载 作者:行者123 更新时间:2023-11-28 20:33:29 24 4
gpt4 key购买 nike

我正在使用此处找到的代码 http://blog.blackwhale.at/?p=336创建自定义 activityIndicator在当前版本的 xCode 中。此代码使用一系列 .png数组中的图像,然后以设置的间隔显示它们以创建动画加载图像,然后您可以随时将其放置在屏幕上(假设您可以以某种方式删除它)。

在我的主 ViewController.m 文件中,我的 viewDidLoad 中有以下代码部分:

/* --- START CUSTOM ACTIVITY INDICATOR */
//Create the first status image and the indicator view
UIImage *statusImage = [UIImage imageNamed:@"activity1.png"];
UIImageView *activityImageView = [[UIImageView alloc]
initWithImage:statusImage];


//Add more images which will be used for the animation
activityImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"activity1.png"],
[UIImage imageNamed:@"activity2.png"],
[UIImage imageNamed:@"activity3.png"],
[UIImage imageNamed:@"activity4.png"],
[UIImage imageNamed:@"activity5.png"],
[UIImage imageNamed:@"activity6.png"],
[UIImage imageNamed:@"activity7.png"],
[UIImage imageNamed:@"activity8.png"],
[UIImage imageNamed:@"activity9.png"],
[UIImage imageNamed:@"activity10.png"],
[UIImage imageNamed:@"activity11.png"],
[UIImage imageNamed:@"activity12.png"],
nil];


//Set the duration of the animation (play with it
//until it looks nice for you)
activityImageView.animationDuration = 0.6;


//Position the activity image view somewhere in
//the middle of your current view
activityImageView.frame = CGRectMake(
self.view.frame.size.width/2
-statusImage.size.width/2,
self.view.frame.size.height/1.2
-statusImage.size.height/1.2,
statusImage.size.width,
statusImage.size.height);

//Start the animation
[activityImageView startAnimating];


//Add your custom activity indicator to your current view
[self.view addSubview:activityImageView];


/* --- END CUSTOM ACTIVITY INDICATOR */

我想清除/删除/隐藏 activityImageView元素,因为我只希望它在应用程序首次启动时显示,直到 UIWebView完成加载。

我想调用它并在 webViewDidStartLoad 时显示 gif然后在 webViewDidFinishLoad 时清除.有人帮忙吗??

最佳答案

你应该这样走:

- (void)viewDidLoad {
[super viewDidLoad];

//Create the first status image and the indicator view
UIImage *statusImage = [UIImage imageNamed:@"activity1.png"];
UIImageView *activityImageView = [[UIImageView alloc]
initWithImage:statusImage];


//Add more images which will be used for the animation
activityImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"activity1.png"],
[UIImage imageNamed:@"activity2.png"],
[UIImage imageNamed:@"activity3.png"],
[UIImage imageNamed:@"activity4.png"],
[UIImage imageNamed:@"activity5.png"],
[UIImage imageNamed:@"activity6.png"],
[UIImage imageNamed:@"activity7.png"],
[UIImage imageNamed:@"activity8.png"],
[UIImage imageNamed:@"activity9.png"],
[UIImage imageNamed:@"activity10.png"],
[UIImage imageNamed:@"activity11.png"],
[UIImage imageNamed:@"activity12.png"],
nil];


//Set the duration of the animation (play with it
//until it looks nice for you)
activityImageView.animationDuration = 0.6;


//Position the activity image view somewhere in
//the middle of your current view
activityImageView.frame = CGRectMake(
self.view.frame.size.width/2
-statusImage.size.width/2,
self.view.frame.size.height/1.2
-statusImage.size.height/1.2,
statusImage.size.width,
statusImage.size.height);

//Start the animation
[activityImageView startAnimating];


//Add your custom activity indicator to your current view
[self.view addSubview:activityImageView];

self.timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0)
target:self
selector:@selector(loading)
userInfo:nil
repeats:YES];

}

- (void)loading {

if (!self.webView.loading) {
[activityImageView stopAnimating];
activityImageView.hidden = 1;
} else {
[activityImageView startAnimating];
}

}

关于objective-c - XCode 自定义事件指示器 - 在 UIWebView 加载后隐藏 (webViewDidFinishLoad),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11421453/

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