2009-11-01 61 views

回答

13

執行此操作的「快速」方法是取UIAlertView並重新定位其內部子視圖以將其進度條推入其中。這個缺點是脆弱的,未來可能會破裂。

要做到這一點,正確的方法需要實現UIWindow的子類,並將其設置爲UIWindowLevelAlert,以使其在當前窗口前繪製。讓一些東西工作起來應該相當容易,但讓它看起來像內置警報之一將需要很多努力。

在你做任何一個之前,我會建議你重新考慮你的用戶界面。上傳時,爲什麼應用程序會阻塞?爲什麼不只是在屏幕上放置一個狀態欄,並讓用戶在異步上傳過程中與應用程序保持交互。看一下消息應用程序在上傳MMS時的工作原理,以瞭解我所談論的內容。

當應用程序阻止某些事情發生時,用戶討厭它,特別是在沒有多任務處理的iPhone上。

+2

+1指出用戶在iPhone的期望。閱讀人機界面指南瞭解更多信息:http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html – Tim 2009-11-01 05:29:18

+0

我需要一個alertView,因爲我想在裏面放一個取消按鈕警報視圖。多數民衆贊成用戶可以取消上傳。 – faisal 2009-11-01 06:18:05

+0

你可以有一個取消按鈕,並把它放在主界面的其他地方,這沒有什麼錯。相信我,你不希望這是一個警報。你真的希望你的用戶在通過EDGE連接上傳數據時坐在那裏盯着警報嗎?如果你這樣做的話,我保證你的用戶會很多地點擊取消按鈕,但那不是一件好事,因爲他們會因爲無聊或沮喪而擊中它。 – 2009-11-01 06:51:06

0

你也可以繼承的UIAlertView中。我做了這樣的事情,改變它的需要。

頭文件,

#import <Foundation/Foundation.h> 

/* An alert view with a textfield to input text. */ 
@interface AlertPrompt : UIAlertView  
{ 
    UITextField *textField; 
} 

@property (nonatomic, retain) UITextField *textField; 
@property (readonly) NSString *enteredText; 

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okButtonTitle; 

@end 

源代碼,

#import "AlertPrompt.h" 


@implementation AlertPrompt 

static const float kTextFieldHeight  = 25.0; 
static const float kTextFieldWidth  = 100.0; 

@synthesize textField; 
@synthesize enteredText; 

- (void) drawRect:(CGRect)rect { 
    [super drawRect:rect]; 

    CGRect labelFrame; 
    NSArray *views = [self subviews]; 
    for (UIView *view in views){ 
     if ([view isKindOfClass:[UILabel class]]) { 
      labelFrame = view.frame; 
     } else {  
      view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y + kTextFieldHeight , view.frame.size.width, view.frame.size.height); 
     } 

    } 

    CGRect myFrame = self.frame; 
    self.textField.frame = CGRectMake(95, labelFrame.origin.y+labelFrame.size.height + 5.0, kTextFieldWidth, kTextFieldHeight); 
    self.frame = CGRectMake(myFrame.origin.x, myFrame.origin.y, myFrame.size.width, myFrame.size.height + kTextFieldHeight); 

} 

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle 
{ 

    if (self = [super initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil]) 
    { 
     // add the text field here, so that customizable from outside. But set the frame in drawRect. 
     self.textField = [[UITextField alloc] init]; 
     [self.textField setBackgroundColor:[UIColor whiteColor]]; 
     [self addSubview: self.textField]; 

     // CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 20.0); 
     // [self setTransform:translate]; 
    } 
    return self; 
} 
- (void)show 
{ 
    [textField becomeFirstResponder]; 
    [super show]; 
} 
- (NSString *)enteredText 
{ 
    return textField.text; 
} 
- (void)dealloc 
{ 
    [textField release]; 
    [super dealloc]; 
} 
@end