AssistoLab / KVNProgress

KVNProgress is a fully customizable progress HUD that can be full screen or not.
MIT License
1.24k stars 202 forks source link

When using displayOnView with a tableview it displays the HUD in the corner of the view #80

Open ezhes opened 8 years ago

ezhes commented 8 years ago

simulator screen shot jul 3 2016 9 46 00 pm

I get this weird bug when I use this KVNProgress.show(withStatus: message, on: self.view) however without the on: self.view it displays correctly. This could be an issue on my end and I'm trying to figure out if anyone else can reproduce.

kevin-hirsch commented 8 years ago

Hello @shusain93 !

Could you show me where in your code you are calling the show method, please?

ezhes commented 8 years ago

It doesn't matter where I call it from the looks of it. I get this: simulator screen shot jul 7 2016 9 45 44 am

when I call it in my pulledToRefresh IBAction

@IBAction func pulledToRefersh(_ sender: AnyObject) {
        KVNProgress.show(withStatus: "ASDASD", on: self.view)
    }
kevin-hirsch commented 8 years ago

Ok. And if you don't add the on view parameter?

ezhes commented 8 years ago

It works correctly/as expected. I'm trying to use the onView so that It doesn't always block the whole view.

kevin-hirsch commented 8 years ago

Ok, I will investigate that!

kevin-hirsch commented 8 years ago

Could you print the type of self.view?

ezhes commented 8 years ago

self.view is a UIView? however even if I use on: self.view! it still doesn't work. If I send my self.tableView I also get the same issue.

kevin-hirsch commented 8 years ago

And if you try in another view controller that is not backed by a tableview?

ezhes commented 8 years ago

That's the bug right there! It seems that a UITableViewController causes the issue because I believe that self.view will return the tableview if it is a UITableViewController

kevin-hirsch commented 8 years ago

Did you print the type of the view like this:

print(self.view)
print(self.view.type)

because I think that UITableViewController has actually a UITableWrapperView or something like that that have the UITableView as child.

ezhes commented 8 years ago

I used a breakpoint and used the object inspector. Using print(self.view.dynamicType) I get ImplicitlyUnwrappedOptional<UIView> and print(self.view) I get <UITableView: 0x7c8ce200; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x7bfc6b30>; layer = <CALayer: 0x7bed7450>; contentOffset: {0, 0}; contentSize: {375, 0}>

So I'd assume that there is no wrapper. .type no longer works in Swift 3.

kevin-hirsch commented 8 years ago

Thanks. I think that adding a subview to a UITableView is unadvised because it can trigger weird behaviours like this one. I'll check what can be done ;)

kevin-hirsch commented 8 years ago

It seems that using Autolayout when adding a subview to a UITableView is messing the subview. When adding the KVNProgress to the view, I add the following constraints:

V:|[loader]|
H:|[loader]|

Commenting the related code gives the correct result:

result

I will see what I can do to fix this.

kevin-hirsch commented 8 years ago

By putting the Autolayout code in an if condition for UITableView cases, it now works. The only thing you have to notice is that you can still scroll through your tableView if you do not prevent it:

bug

I will check that nothing is broken before committing it 🙃

kevin-hirsch commented 8 years ago

Ok, I made a commit on master 626b9a9 You can check it out and test it 😉 With CocoaPods, you can do:

pod 'KVNProgress', :git => 'https://github.com/AssistoLab/KVNProgress.git', :commit => '626b9a943d'

I wait for your feedback before closing this issue.

ezhes commented 8 years ago

Thanks!

This works perfectly as long as every single other use of the progress spinner is also used with the on: property. If you end up mixing them in the same view controller you end up breaking the whole shared object and so every time it presents using on: it shows up like this:

img_2641

and we are thrown an autolayout error in the console:

[LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x170099dc0 UIImageView:0x101127d10.width == - 50   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x170099dc0 UIImageView:0x101127d10.width == - 50   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

edit: It doesn't seem like the on: attribute is directly connected. I still see this issue after having fixed all of the occurrences.

kevin-hirsch commented 8 years ago

Hello @shusain93! So it works well, but not when you use the show method without the on: parameter? Could you be more precise, please? :)