标签: uiactivityindicatorview

初学者在iPhone上常见的多线程错误

我刚刚在我的应用程序中引入了多线程,以获得一个愚蠢的UIActivityIndi​​catorView.好吧,活动指示器工作正常 - 但现在我的应用程序有时会崩溃,有时它不会 - 在其他条件控制的情况下......我需要弄清楚这一点,但不知道从哪里开始寻找......

那么,初学者在iPhone上多线程经常会犯一些常见错误?请具体说明您的答案.谢谢你的时间.

更新:我添加了有问题的来源以供参考.

//--------------------Where the multithreading starts------------------------


-(IBAction)processEdits:(id)sender
{
        //Try to disable the UI to prevent user from launching duplicate threads
    [self.view setUserInteractionEnabled:NO];

        //Initialize indicator (delcared in .h)
    myIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(155, 230, 20, 20)];
    myIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    [self.view addSubview:myIndicator];
    [self.view bringSubviewToFront:myIndicator];
    [myIndicator startAnimating];


    //Prepare and set properties of the NEXT modal view controller to switch to
    controller = [[EndViewController alloc] initWithNibName:@"EndViewController" bundle:nil];

    controller.delegate = self;

    [self performSelectorInBackground:@selector(threadWork:) withObject:nil];


}



//-----------------------------THE THREAD WORK--------------------------------


-(IBAction)threadWork:(id)sender{ …
Run Code Online (Sandbox Code Playgroud)

iphone multithreading uikit uiactivityindicatorview

8
推荐指数
2
解决办法
1万
查看次数

iPhone UIActivityIndi​​catorView无法启动或停止

当我在UIActivityIndi​​catorView上调用startAnimating时,它无法启动.为什么是这样?

[这是一个博客风格的自我回答的问题.下面的解决方案对我有用,但也许还有其他更好的方法?]

iphone uiactivityindicatorview

8
推荐指数
2
解决办法
2万
查看次数

以编程方式向视图添加活动指示器

可能重复:
在应用程序启动期间显示活动指示

所有,

在我的app委托中,我创建了一个使用我的Default.png的动画启动视图.一切正常,但我无法弄清楚如何让我的ActivityIndi​​cator显示在初始视图之上.它只是被飞溅视图隐藏起来.这是我拥有和感谢:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 //... data access stuff here ...

 self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

// ... more setup stuff here ...



/****************************************************************************
 *
 *
 * Splash Screen for iPhone
 *
 ****************************************************************************/
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {


    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
    splashView.image = [UIImage imageNamed:@"Default.png"];
    [self.window addSubview:splashView];
    [self.window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    splashView.alpha = 0.0;
    splashView.frame = CGRectMake(-60, -60, …
Run Code Online (Sandbox Code Playgroud)

uiactivityindicatorview uiapplicationdelegate ios

8
推荐指数
1
解决办法
3万
查看次数

当应用暂停时,为什么活动指示仍然会旋转?

我用一个按钮和一个活动指示器创建了一个简单的应用程序.当我按下按钮时,我有活动指示器开始动画.在Xcode 4.6 iPhone 6.1 Simulator中,我看到活动指示器正在旋转.当我暂停应用程序时,我有时会进入libsystem_kernel.dylib`mach_msg_trap.这似乎是在com.apple.main-thread上,它是线程1.不应该以这种方式暂停应用程序阻止主线程,因此阻止活动指示器旋转?它似乎没有.

更新:本文(http://www.dragthing.com/blog/2009/07/how-to-make-your-iphone-app-launch-faster/)说"我发现,UIActivityIndi​​catorView动画是在系统的一个线程 - 这意味着,即使我的应用程序在启动时在其初始化代码中被阻塞,微调器仍然会旋转.是否有可能将UIActivityIndi​​catorView设置为主线程的动画?

xcode breakpoints objective-c uiactivityindicatorview ios

8
推荐指数
1
解决办法
952
查看次数

启动和停止活动指示器swift3

我正在学习Swift,现在正在完成我的家庭任务.我的一个按钮调用一个函数,我重新加载一个集合视图,这需要时间.我正在尝试实施一个活动指示器来显示该过程.问题是,如果我启动指示器,加载集合视图,然后在按钮操作中停止指示器,则指示器不会出现.在这种情况下,实施指标的正确方法是什么?这是代码片段:

let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
@IBOutlet weak var onCIFilterView: UICollectionView!
@IBOutlet var cifilterMenu: UIView!

@IBAction func onCIFiltersButton(_ sender: UIButton) {
    if (sender.isSelected) {
        hideCIFilters()
        sender.isSelected = false
    }
    else {
        activityIndicator.startAnimating()
        showCIFilters()  //the menu with UIView collection
        activityIndicator.stopAnimating()
        sender.isSelected = true
    }
}

func showCIFilters () {
    onCIFilterView.reloadData() // reloading collection view
    view.addSubview (cifilterMenu)
    let bottomConstraint = cifilterMenu.bottomAnchor.constraint(equalTo: mainMenu.topAnchor)
    let leftConstraint = cifilterMenu.leftAnchor.constraint(equalTo: view.leftAnchor)
    let rightConstraint = cifilterMenu.rightAnchor.constraint(equalTo: view.rightAnchor)
    let heightConstraint = cifilterMenu.heightAnchor.constraint(equalToConstant: 80)
    NSLayoutConstraint.activate([bottomConstraint, leftConstraint, rightConstraint, heightConstraint])
    view.layoutIfNeeded() …
Run Code Online (Sandbox Code Playgroud)

uiactivityindicatorview ios swift

8
推荐指数
1
解决办法
1万
查看次数

如何将活动指标添加到WKWebView(Swift 3)

我的应用程序中有一个wkwebview,我想为它添加一个活动指示器.我希望它能够在webview加载时出现,并在加载完成后消失,它会消失.你能给我一些代码吗?这是我现在的代码:

@IBOutlet weak var Activity: UIActivityIndicatorView!
var webView : WKWebView!


@IBOutlet var containerView: UIView? = nil


override func viewDidLoad() {
    super.viewDidLoad()

    guard let url = URL(string: "http://ifunnyvlogger.wixsite.com/ifunnyvlogger/app-twitter") else { return }

    webView = WKWebView(frame: self.view.frame)
    webView.translatesAutoresizingMaskIntoConstraints = false
    webView.isUserInteractionEnabled = true
    webView.navigationDelegate = self

    self.view.addSubview(self.webView)

    let request = URLRequest(url: url)
    webView.load(request)

}


func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {

    // Check if a link was clicked
    if navigationAction.navigationType == .linkActivated {

        // Verify the …
Run Code Online (Sandbox Code Playgroud)

uiactivityindicatorview ios wkwebview swift3

8
推荐指数
3
解决办法
2万
查看次数

iOS:UISearchBar中的UIActivityIndi​​cator

是否可以在搜索时在UISearchBar中显示UIActivityIndi​​cator?

search xcode uisearchbar uiactivityindicatorview ios

7
推荐指数
3
解决办法
6775
查看次数

UIRefreshControl更改UIActivityIndi​​catorView的颜色

有什么办法可以改变UIRefreshControl的"UIActivityIndi​​catorView"的颜色吗?

我没找到任何东西!

谢谢!!

UIRefreshControl

xcode colors objective-c uiactivityindicatorview uirefreshcontrol

7
推荐指数
2
解决办法
7476
查看次数

显示微调器并将其移除到同一个块中

在一个可能需要几秒钟的方法中,我有:

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(135,140,50,50)];
spinner.color = [UIColor blueColor];
[spinner startAnimating];
[_mapViewController.view addSubview:spinner];

// lots of code

[spinner removeFromSuperview];
Run Code Online (Sandbox Code Playgroud)

微调器没有显示出来.可能是因为当时屏幕没有得到更新.我该如何解决这个问题?

uiactivityindicatorview ios

7
推荐指数
1
解决办法
2万
查看次数

如何以编程方式放置我的activityIndi​​cator?

我想将我的activityIndi​​cator放置在需要编程的地方,但是我不知道怎么做。

我知道如何将其放在屏幕中央:

activityIndicator.center = self.view.center
Run Code Online (Sandbox Code Playgroud)

但是我想要这样的东西:

activityIndicator.activityIndicator(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
Run Code Online (Sandbox Code Playgroud)

但是我似乎无法使它起作用。

activity-indicator uiactivityindicatorview swift swift3

7
推荐指数
3
解决办法
6944
查看次数