UIAlertController/UIAlertView scrolling on iOS 8

前端 未结 5 952
旧巷少年郎
旧巷少年郎 2020-12-31 16:41

I\'m wondering if anyone knows a good solution to the fact that UIAlertViews and UIAlertControllers won\'t scroll on iOS 8? Here is an example:

[[[UIAlertVie         


        
相关标签:
5条回答
  • 2020-12-31 16:53

    cafedeichi's solution didn't work for me, so I ended up using DTAlertView which works both on iOS 8 and iOS 7.

    0 讨论(0)
  • 2020-12-31 16:59

    Although I dunno the right way, I could solve the issue anyway. Seems like the view scrolls if you set the frame property (but not CGRectZero). It worked fine on iOS 8.0.2.

    NSString* messageString = @"long string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\n";
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title"
                                                                             message:messageString
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    alertController.view.frame = [[UIScreen mainScreen] applicationFrame];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@“OK”
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action){
                                                          [self okButtonTapped];
                                                      }]];
    [self presentViewController:alertController animated:YES completion:nil];
    
    //——
    - (void) okButtonTapped{};
    
    0 讨论(0)
  • 2020-12-31 17:03

    The problem has been fixed on iOS 8.3 I've been using cafedeichi solution, but if isn't working on landscape mode for iPhones and iPod touch devices, and if you add a textfield it will crash on iOS 8.3, so I'm using this code right now that fixes the two problems mentioned:

    NSString* messageString = @"long string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\n";
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title"
                                                                             message:messageString
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.3) {
    
        CGFloat screenHeight;
        CGFloat screenWidth;
        if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortraitUpsideDown){
            screenHeight = [UIScreen mainScreen].applicationFrame.size.height;
            screenWidth = [UIScreen mainScreen].applicationFrame.size.width;
        } else{
            screenHeight = [UIScreen mainScreen].applicationFrame.size.width;
            screenWidth = [UIScreen mainScreen].applicationFrame.size.height;
        }
        CGRect alertFrame = CGRectMake([UIScreen mainScreen].applicationFrame.origin.x, [UIScreen mainScreen].applicationFrame.origin.y, screenWidth, screenHeight);
                alertController.view.frame = alertFrame;
    
    }
    
    [alertController addAction:[UIAlertAction actionWithTitle:@“OK”
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action){
                                                          [self okButtonTapped];
                                                      }]];
    [self presentViewController:alertController animated:YES completion:nil];
    
    //——
    - (void) okButtonTapped{};
    
    0 讨论(0)
  • 2020-12-31 17:09

    Any UIAlertView instances have to first be changed to UIAlertController instances. (They can be used pretty much the same way.) After changing it to a UIAlertController, set the frame property to the application main screen. (setting view.frame of UIAlertView doesn't help) Evidently, they are depreciating UIAlertViews in IOS8, although it isn't as clear as it should be.

    0 讨论(0)
  • 2020-12-31 17:17

    Use this :

    NSString *message = @"YOUR LONG MESSAGE" ;    
    NSInteger lines = [[message componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] count];
    
        UITextView *txtView = nil ;
        if (lines > MAX_LINES_TO_SHOW)
        {
            txtView = [[UITextView alloc] init];
            [txtView setBackgroundColor:[UIColor clearColor]];
            [txtView setTextAlignment:NSTextAlignmentCenter] ;
            [txtView setEditable:NO];
            [txtView setText:message];
        }
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] ;
        [alert setValue:txtView forKey:@"accessoryView"];
        [alert setTag:tag] ;
        [alert show] ;
    
    0 讨论(0)
提交回复
热议问题