10.1 C
Friday, December 8, 2023

ios – UIImagePickerController Taking Seconds to Seem

On my app, I’ve two UIImageViews with interplay enabled. They every initially load with a placeholder picture. Tapping them is meant to open the picture picker controller. Deciding on a picture lets them crop it and select, at which level the UIImageView picture modifications to that. This all works, however it’s round 3-5 seconds AFTER tapping the UIImageView earlier than the controller seems. I examined this with only a easy UIButton as nicely, nevertheless it had the identical outcomes. On a separate view controller I attempted it, and it was instantaneous, even with the very same code. What am I lacking?

- (void)viewDidLoad {
    [super viewDidLoad];
    UITapGestureRecognizer *tapGestureRecognizer1 = [[UITapGestureRecognizer alloc] initWithTarget:self motion:@selector(selectImageForFirstImageView:)];
    tapGestureRecognizer1.numberOfTapsRequired = 1;

       [self.firstImageView addGestureRecognizer:tapGestureRecognizer1];
       self.firstImageView.userInteractionEnabled = YES;
       UITapGestureRecognizer *tapGestureRecognizer2 = [[UITapGestureRecognizer alloc] initWithTarget:self motion:@selector(selectImageForSecondImageView:)];
    tapGestureRecognizer2.numberOfTapsRequired = 1;

       [self.secondImageView addGestureRecognizer:tapGestureRecognizer2];
       self.secondImageView.userInteractionEnabled = YES;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.pdfFileArray = [NSMutableArray array];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    self.firstImageView.picture = [UIImage imageNamed:@"naughtyplaceholder"];
        self.secondImageView.picture = [UIImage imageNamed:@"niceplaceholder"];
    self.firstImageView.tag = 1;
        self.secondImageView.tag = 2;

    // Arrange your proper bar button merchandise
    UIBarButtonItem *buildButton = [[UIBarButtonItem alloc] initWithTitle:@"Construct" model:UIBarButtonItemStylePlain goal:self motion:@selector(buildPDF)];
    self.navigationItem.rightBarButtonItem = buildButton;
    NSFileManager *fileManager = [NSFileManager defaultManager];

    NSDate *currentDate = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *parts = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth) fromDate:currentDate];
    NSInteger currentYear = [components year];
       NSInteger currentMonth = [components month];
       if (currentMonth <= 7) {
           currentYear -= 1; // If it is August or later, increment the yr
    // Extract the yr and month parts
    NSInteger yr = [components year];

    // Get the entered title from the textField

    // Create the folder path primarily based on the yr
    NSString *folderPath = [NSString stringWithFormat:@"%@/NaughtyNice/%@", [self documentsDirectory], [@(currentYear) stringValue]];
    NSArray *recordsdata = [fileManager contentsOfDirectoryAtPath:folderPath error:nil];
    NSPredicate *pdfFilter = [NSPredicate predicateWithFormat:@"self ENDSWITH '.pdf'"];
    NSArray *pdfFiles = [files filteredArrayUsingPredicate:pdfFilter];
    // Assuming pdfFileArray is an NSMutableArray to retailer PDF file names
    NSLog(@"Naughty Path %@", folderPath);

    self.pdfFileArray = [NSMutableArray arrayWithArray:pdfFiles];

    NSLog(@"PDF File Array Depend: %lu", (unsigned lengthy)self.pdfFileArray.depend);

    [self.tableView reloadData];

- (void)selectImageForFirstImageView:(UITapGestureRecognizer *)gesture {
    [self presentImagePickerForImageView:self.firstImageView];

- (void)selectImageForSecondImageView:(UITapGestureRecognizer *)gesture {
    [self presentImagePickerForImageView:self.secondImageView];

- (void)presentImagePickerForImageView:(UIImageView *)imageView {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.allowsEditing = YES;

    // Set a tag or different identifier to differentiate between picture views
    imagePicker.view.tag = imageView.tag;

    [self presentViewController:imagePicker animated:YES completion:nil];

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)information {
    UIImage *selectedImage = information[UIImagePickerControllerEditedImage];

    // Assign the chosen picture to the suitable UIImageView
    if (picker.view.tag == self.firstImageView.tag) {
        self.firstImageView.picture = selectedImage;
    } else if (picker.view.tag == self.secondImageView.tag) {
        self.secondImageView.picture = selectedImage;

    [picker dismissViewControllerAnimated:YES completion:nil];

Latest news
Related news


Please enter your comment!
Please enter your name here