2012-08-13 59 views
0

當我嘗試將ATMHud添加到uitableviewcontroller子視圖它確實工作,但它不會禁用滾動,如果tableview不是頂部我看不到hud視圖。我所做的是添加到tabBarController.view工作,但我想知道如果這是一個好主意或稍後我可能會遇到問題。是否有意義添加ATMHud tabBarController.view

另一個問題是tabBarController.view框架是整個屏幕或只是底部的一部分。如何在屏幕中間顯示atmhud?

在此先感謝!

============ 發現了一個博客帖子裏介紹如何重置self.view並分別在UITableViewController中

UITableViewController and fixed sub views

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    if (!tableView && 
     [self.view isKindOfClass:[UITableView class]]) { 
      tableView = (UITableView *)self.view; 
    } 

    self.view = [[[UIView alloc] initWithFrame: 
     [UIScreen mainScreen].applicationFrame] autorelease]; 
    self.tableView.frame = self.view.bounds; 
    self.tableView.contentInset = UIEdgeInsetsMake(44.0, 0.0, 0.0, 0.0); 
    [self.view addSubview:self.tableView]; 

    UIView *fixedBar = [[UIView alloc] initWithFrame: 
     CGRectMake(0.0, 0.0, self.view.bounds.size.width, 44.0)]; 
    fixedBar.backgroundColor = [UIColor colorWithRed: 
     0.0 green:1.0 blue:0.0 alpha:0.7]; 
    [self.view addSubview:fixedBar]; 
    [fixedBar release];      
} 
添加的tableview

在此之後,將hud添加到self.view時,您將能夠禁用底部的tableview。 讓我知道這是一個很好的方式來設置表視圖

回答

1

使用標籤欄的問題是,hud現在是模式,並且用戶不能更改選項卡。

這聽起來像tableview不是你的主要視圖,因爲它可以「掩蓋」。如果它不是主要視圖,則將ATMHud添加到self.view。如果tableView與self.view相同,則爲其添加一個新的透明視圖,然後將HUD添加到該視圖。如果你想看看它的大小(或框架),使用NSStringFromCGRect(self.tabBarController.frame)來記錄它;如果你想查看它的大小(或框架),請使用NSStringFromCGRect(self.tabBarController.frame)。

編輯:我只是做了一個測試,ATMHud阻止用戶界面。所有我能想到的是,你需要你尚未插入它,我有一個示範項目,我做的這個地方(在當前視圖的子視圖的頂部。):

hud = [[ATMHud alloc] initWithDelegate:self]; 
[self.view addSubview:hud.view]; 
[hud setCaption:@"Howdie"]; 
[hud setActivity:YES]; 
[hud show]; 
[hud hideAfter:5]; 

的HUD下的按鈕不主動 - 在視圖中其實沒有什麼是積極的(可能是導航欄會雖然現場)

如果你想要一個ARCified和現場測試的版本,你可以抓住它here

EDIT2:解決你的問題在下面。需要注意的是ATMHud阻止越來越表點擊,和下面的代碼停止滾動:

- (void)hudWillAppear:(ATMHud *)_hud 
{ 
    self.tableView.scrollEnabled = NO; 
} 
- (void)hudDidDisappear:(ATMHud *)_hud 
{ 
    self.tableView.scrollEnabled = YES; 
} 

轉儲觀點:

#import <QuartzCore/QuartzCore.h> 

#import "UIView+Utilities.h" 

@interface UIView (Utilities_Private) 

+ (void)appendView:(UIView *)v toStr:(NSMutableString *)str; 

@end 

@implementation UIView (Utilities_Private) 

+ (void)appendView:(UIView *)a toStr:(NSMutableString *)str 
{ 
    [str appendFormat:@" %@: frame=%@ bounds=%@ layerFrame=%@ tag=%d userInteraction=%d alpha=%f hidden=%d\n", 
     NSStringFromClass([a class]), 
     NSStringFromCGRect(a.frame), 
     NSStringFromCGRect(a.bounds), 
     NSStringFromCGRect(a.layer.frame), 
     a.tag, 
     a.userInteractionEnabled, 
     a.alpha, 
     a.isHidden 
     ]; 
} 

@end 

@implementation UIView (Utilities) 

+ (void)dumpSuperviews:(UIView *)v msg:(NSString *)msg 
{ 
    NSMutableString *str = [NSMutableString stringWithCapacity:256]; 

    while(v) { 
     [self appendView:v toStr:str]; 
     v = v.superview; 
    } 
    [str appendString:@"\n"]; 

    NSLog(@"%@:\n%@", msg, str); 
} 

+ (void)dumpSubviews:(UIView *)v msg:(NSString *)msg 
{ 
    NSMutableString *str = [NSMutableString stringWithCapacity:256]; 

    if(v) [self appendView:v toStr:str]; 
    for(UIView *a in v.subviews) { 
     [self appendView:a toStr:str]; 
    } 
    [str appendString:@"\n"]; 

    NSLog(@"%@:\n%@", msg, str); 
} 

@end 
+0

感謝您的答覆。沒有意識到,這使得標籤欄凍結。我想有沒有簡單的方法可以將視圖放在tableview之上,如果它是一個uitableviewcontroller。當我添加到self.view它添加到tableview,但不凍結它,你可以滾動它離屏。我不知道這是一個問題還是標題讓我失望投票? – Yan 2012-08-14 02:14:27

+1

我正在使用這個類(我在github上有一個分支),它非常棒。在添加HUD來攔截用戶操作之前,我不得不添加自己的觀點,但是當我看着ATMHud時,它也是這樣做的。我需要進一步調查...我很快就會回到這裏。 – 2012-08-14 10:38:06

+0

再次感謝您的回覆。我認爲這隻發生在我有一個表視圖控制器。當我有一個帶有taleview的普通viewcontroller,並且我有[self.view addsubivew:hud.view],那麼ATMHud會攔截用戶操作。我在這裏閱讀了一些帖子,很難在tableview控制器中放置tableview頂部的視圖。不知道這是否正確。 – Yan 2012-08-14 13:42:14