我有一个场景,我在 UITableViewController 上使用第三方库MBProgressHUD但问题是我每次向上和向下滚动HUD都会随着滚动一起移动。
我不想禁用UITableView滚动,我也希望将HUD保持在UITableView的中心。
有可能实现它吗?
答案 0 :(得分:6)
将HUD添加到tableview的超级视图或navigationController.view
可以解决问题:
UIView *view = self.tableView.superview;
// UIView *view = self.navigationController.view; if you are using navigationController
if (view != nil) {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
}
答案 1 :(得分:0)
问题可能是您要在tableview中添加HUD,以便在您的视图中添加...
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = @"Loading";
}
答案 2 :(得分:0)
创建MBProgressHUD的对象(例如:MBProgressHUD * HUD)。初始化它并在主视图上添加HUD作为子视图并执行此操作
[HUD setCenter:self.view.center];
[HUD setUserInteractionEnabled:YES];
答案 3 :(得分:0)
是的,有一种可能的解决方法。在[HUD show:YES]
之前,请添加此代码。
HUD.yOffset = CGRectGetMinY(self.tableView.bounds);
就是这样。
看起来HUD
的{{1}}被设置为超级浏览的view.frame
,因此如果向下滚动然后显示frame
,则位置错误。添加该行会将HUD
的{{1}}添加到向下滚动的数量。
答案 4 :(得分:0)
这对我有用。将其设置为parentViewController,然后查看。
plugins {
id "nebula.ospackage" version "3.2.0"
}
apply plugin: 'nebula.ospackage'
apply plugin: 'java'
apply plugin: "jacoco"
repositories {
mavenCentral()
jcenter()
}
dependencies {
testCompile 'org.testng:testng:6.8'
compile 'log4j:log4j:1.2.17'
}
sourceSets {
main {
java { srcDir 'src/main/java/' }
resources { srcDir 'src/main/resources' }
}
test {
java { srcDir 'src/test/java/' }
resources { srcDir 'src/test/resources' }
}
}
test {
// explicitly include or exclude tests
include 'src/test/java/**'
useTestNG{
useDefaultListeners = true
}
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
finalizedBy jacocoTestReport
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.enabled true
html.destination "${buildDir}/jacocoHtml"
}
}
jar {
baseName = 'smith'
version = '1.0'
manifest {
attributes 'Main-Class': 'src.main.java.HelloWorld '}
}
ospackage {
packageName = 'foo'
version = '1.2.3'
release = '1'
arch = I386
os = LINUX
}
// buildRpm and buildDeb are implicitly created, but can still be configured if needed
buildRpm {
arch = I386
}
答案 5 :(得分:0)
我尝试按照上面的说明将它添加到导航控制器中,当我将其翻译为swift时,我得到了一些解包错误。我发现this fix并且每次都有效。感谢Aleksei Kaut: - )。
- (void)showLoadingIndicator
{
[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
}
- (void)hideLoadingIndicator
{
[MBProgressHUD hideAllHUDsForView:[UIApplication sharedApplication].keyWindow animated:YES];
}
答案 6 :(得分:0)
Swift 3.0
override func viewDidLoad() {
super.viewDidLoad()
progress = MBProgressHUD(view: view) // <<-- That's the trick
view.addSubview(progress!)
view.bringSubview(toFront: progress!)
progress?.show(animated: true)
progress?.mode = .indeterminate
progress?.animationType = .fade
}
答案 7 :(得分:0)
解决方案很简单。当您使用tableView时,只需将MBProgressHUD附加到UIApplication.shared.delegate?.window
对于swift 3.0:
显示MBProgressHUD
MBProgressHUD.showAdded(to: ((UIApplication.shared.delegate?.window)!)!, animated: true)
隐藏MBProgressHUD
MBProgressHUD.hide(for: ((UIApplication.shared.delegate?.window)!)!, animated: true)