Red distorting screen

I've got a fucking time to figure this out.

I have a modal view that appears when I click on one of the tabs in the tab bar. The new view, which spans the entire screen, has a button that the user enters to start recording audio, and when they finish recording audio or cancel recording, the modal view is rejected.

The problem is that after starting recording, this new recording pane should appear on this new view. But this is not the case. And once that opinion is dismissed, in the next view presented (a table view that is on one of the tabs), you can see a red record bar at the top for a second of a second, and it disappears, BUT it pushes the tab bar down the screen and obscures part of the tab bar, which you can see in the third screenshot below.

Modal view pops up - recording is currently in progress, but red recording indicator is not showing at the top A modal view will appear - recording is currently in progress, but the red recording indicator does not appear at the top

Right when the recording is done and the view is about to disappear, the red bar appears That's right, when the recording is complete and the view is about to disappear, a red bar will appear

And once the view disappears and we're left with the table view that lives in one of the tabs, the tab bar is shoved down past the bottom of the screen :( And as soon as the view disappears and we're left with a table view that lives on one of the tabs, the tab bar slides down the bottom of the screen :( SHOULD look like this (with the fourth tab selected): enter image description here

My questions:

1) What am I doing wrong causing the red entry bar to NOT display in a modal view?

2) Is there a way to update this view from the screenshot so that it changes correctly when it appears?

Here is the code. I removed some non-important things that are not relevant to views.

@interface AudioViewController ()

@end

@implementation AudioViewController

@synthesize fileData;

UILabel *countdownLabel;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
    self.recipients = [[NSMutableArray alloc] init];
}


- (void) viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    self.audioPicker = [[UIViewController alloc] init];
    self.audioPicker.view.backgroundColor = [UIColor yellowColor];

    self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
    PFQuery *query = [self.friendsRelation query];
    [query orderByAscending:@"username"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);
        }
        else {
            self.friends = objects;
            [self.tableView reloadData];
        }
    }];

    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    cancelBtn.frame = CGRectMake(50.0, 200.0, 200.0, 200.0);
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:20];
    [cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal];
    [self.audioPicker.view addSubview:cancelBtn];
    cancelBtn.center = CGPointMake(self.view.center.x, 400);
    [cancelBtn addTarget:self action:@selector(exitRecordingScreen) forControlEvents:UIControlEventTouchUpInside];

    UIButton *recordBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    recordBtn.frame = CGRectMake(50.0, 50.0, 200.0, 200.0);
    recordBtn.titleLabel.font = [UIFont systemFontOfSize:50];
    [recordBtn setTitle:@"Record" forState:UIControlStateNormal];
    recordBtn.center = CGPointMake(self.view.center.x, 100);
    [self.audioPicker.view addSubview:recordBtn];

    if ([self respondsToSelector:@selector(timeout)]) {
        [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeout) userInfo:nil repeats:NO];
    } else {
        NSLog(@"Error: missing selector");
    }

    AVAudioSession *session = [AVAudioSession sharedInstance];

    [session setCategory:AVAudioSessionCategoryPlayAndRecord
             withOptions:AVAudioSessionCategoryOptionDuckOthers
                   error:nil];

    if (!fileData) {
        [self presentViewController:self.audioPicker animated:NO completion:nil];
        NSLog(@"File data: %@", fileData);
        [recordBtn addTarget:self action:@selector(startRecordingAudio) forControlEvents:UIControlEventTouchUpInside];
    } else {
        NSLog(@"Existing File data: %@", fileData);
    }
}

- (void) timeout {

    [self.navigationController popViewControllerAnimated:YES];
}

# pragma mark - Audio Recording Methods

////////
// Removed some stuff here that is not manipulating views
////////

- (void) stopRecordingOnAudioRecorder:(AVAudioRecorder *)paramRecorder{
    /* Just stop the audio recorder here */
    [paramRecorder stop];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder
                           successfully:(BOOL)flag{
    if (flag) {
        NSLog(@"Stopped recording process");
        NSError *playbackError = nil;
        NSError *readingError = nil;
        fileData = [NSData dataWithContentsOfURL:[self audioRecordingPath]
                              options:NSDataReadingMapped
                                error:&readingError];

        self.audioPlayer = [[AVAudioPlayer alloc] initWithData:fileData
                                                         error:&playbackError];

        if (self.audioPlayer != nil) {
            self.audioPlayer.delegate = self;

            //Prepare and start playing
            if ([self.audioPlayer prepareToPlay] && [self.audioPlayer play]) {
                NSLog(@"Started playing recorded audio");
            } else {
                NSLog(@"Couldn't play recorded audio");
            }


        } else {
            NSLog(@"Failed to create audio player");
        }
    } else {
        NSLog(@"Stopping audio recording failed");
    }
    self.audioRecorder = nil;
}

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player
                       successfully:(BOOL)flag{
    if (flag){
        NSLog(@"Audio player stopped correctly.");
    } else {
        NSLog(@"Audio player did not stop correctly.");
    }
    if ([player isEqual:self.audioPlayer]){
        self.audioPlayer = nil;
    } else {
        /* This is not the player */
    }
}

# pragma mark - TableView methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.friends count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    PFUser *user = [self.friends objectAtIndex:indexPath.row];
    cell.textLabel.text = user.username;

    // makes sure checkmark isn't reused if user didn't explicitly select name
    if ([self.recipients containsObject:user.objectId]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

- (void)reset {
    self.audioFile = nil;
}

// User hits "Cancel" button
-(void)exitRecordingScreen {
    [self reset];
    [self.presentedViewController dismissViewControllerAnimated:NO completion:nil];
    [self.tabBarController setSelectedIndex:0];
    NSLog(@"exit recording screen button pressed");

}

- (IBAction)send:(id)sender {
    if (self.audioFile == nil) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Please try again." message:@"Please record audio again to share." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [alertView show];
        [self presentViewController:self.audioPicker animated:NO completion:nil];
    } else {
        [self uploadMessage];
        [self.tabBarController setSelectedIndex:0];
    }
}
// Cancel sending recorded file
- (void)cancel:(id)sender {
    fileData = nil;
    [self reset];
    [self.tabBarController setSelectedIndex:0];
}

@end

      

Sorry for the wall of text and length. I'm really stumped.

+3


source to share


1 answer


Decision. For UITabBarController, you have to reset the frame. 1. Initially, the border for the UITabBarController will be (0,0, screenWidth, screenHeight). 2. But when this red write bar appears, it becomes (0.20, screenWidth, screenHeight) 3. Here you must change the height for the UITabBarController

CGRect changedFrame = objMainTabBarController.view.frame; changedFrame.size.height = [UIScreen mainScreen] .bounds.size.height - CGRectGetMinY (changedFrame); objMainTabBarController.view.frame = changedFrame;



What is it..

+1


source







All Articles