Xin lỗi, các bạn, vì đã sử dụng mục tiêu c, trong giải pháp này, nhưng tôi nghĩ nó có thể giúp những người khác, những người chưa sử dụng Swift. Và, ngoài ra, bạn có thể chuyển đổi nó khá dễ dàng thành Swift. Đó là phương pháp tôi muốn làm nổi bật hơn.
Tôi cũng không chắc liệu Apple có thể từ chối giải pháp này hay không, nhưng ở đây cũng vậy.
Apple tuyên bố rằng từ iOS7 trở đi, UIAlertView không nên được phân loại. Quan điểm phân cấp cho lớp này là tư nhân và không được chỉnh sửa:
https://developer.apple.com/reference/uikit/uialertview?language=objc
Nói cách khác, việc thêm một UIView để một UIAlertView hoàn toàn không có hiệu lực.
Tuy nhiên, tôi có giải pháp liên quan đến việc thêm UIProgressView phía trên UIAlertView, nhưng thêm phần trước vào cửa sổ ứng dụng. Sử dụng UIView superview.center bất động sản, và một số điều chỉnh nhỏ, mong muốn ảnh hưởng có thể đạt được:
-(void)addProgressBar{
float width = 232;
float height = 5;
self.progbar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
self.progbar.backgroundColor = [UIColor colorWithWhite:0.75f alpha:1.0f];
[self.progbar setFrame:CGRectMake(0,0,width,height)];
[self.progbar setTrackTintColor:[UIColor colorWithWhite:0.75f alpha:1.0f]];
[self.progbar setProgressTintColor:[UIColor colorWithRed:21.0f/255.0f green:126.0f/255.0f blue:251.0f/255.0f alpha:1.0f]];
self.progbar.alpha = 0.0;
[[UIApplication sharedApplication].keyWindow addSubview:self.progbar];
self.progbar.center = self.progbar.superview.center;
[self.progbar setFrame:CGRectMake(self.progbar.frame.origin.x,self.progbar.frame.origin.y+10,self.progbar.frame.size.width,self.progbar.frame.size.height)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[self.progbar setAlpha:1.0];
[UIView commitAnimations];
}
tôi thêm các fade in, cho phép UIAlertView xuất hiện đầy đủ đầu tiên. Sau đó thêm một số chức năng đại biểu khác để bỏ qua những UIProgressView, tại những khoảnh khắc chính xác:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(self.alert.cancelButtonIndex == buttonIndex){
[self.progbar removeFromSuperview];
}
}
- (void)alertViewCancel:(UIAlertView *)alertView{
[self.progbar removeFromSuperview];
}
Làm thế nào để bạn cập nhật những tiến bộ? –
Bạn chỉ cần thay đổi "progressView.progress". Có thể rõ ràng hơn để xác định "var progressView: UIProgressView?" bên ngoài (không phải trong khối hoàn thành) là tùy chọn và sau đó đặt "progressView? .progress = 0.123". – coyer
tại sao yo sử dụng hằng số? điều này chỉ nhận được kết quả trực quan khác nhau trên iPhone và iPad. Trên thực tế, chỉ có vẻ tốt trong chân dung iPhone vì trong bối cảnh progressview trông chuyển – Ricardo