简体   繁体   English

界面方向问题 - PopUp

[英]Interface Orientation issue - PopUp

In my app, i have a feature to upload files and for that, i have given a button.在我的应用程序中,我有一个上传文件的功能,为此,我提供了一个按钮。 And if we click in the btn, we ll get a popup with options to select "Choose Photo" or "Take Photo".如果我们点击 btn,我们会看到一个弹出窗口,其中包含选择“选择照片”或“拍照”的选项。 There if we click on the choose photo option, i get an exception如果我们点击选择照片选项,我会得到一个例外

Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES .支持的方向与应用程序没有共同的方向,并且 shouldAutorotate 返回 YES

Here is the code which i have given这是我给出的代码

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

-(IBAction)SettingBtn:(id)sender forEvent:(UIEvent*)event
{
    TSActionSheet *actionSheet = [[TSActionSheet alloc] initWithTitle:@" "];

    [actionSheet addButtonWithTitle:@"Take Photo" block:^{
    NSLog(@"Take Photo");

    [self openCamera];

    }];
    [actionSheet addButtonWithTitle:@"Choose Photo" block:^{
    NSLog(@"Choose Photo");

    [self pick];

    }];

    actionSheet.cornerRadius = 3;
    [actionSheet showWithTouch:event];
}


-(void)openCamera
{

    //[popOverForPicker dismissPopoverAnimated:YES];

    @try
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.navigationBar.tintColor = [UIColor blackColor];
        [self.navigationController presentViewController:picker animated:YES completion:nil];



    }
    @catch (NSException *exception)
    {
        CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"No Camera"
                                                                message:@"Camera is not available  "
                                                               delegate:self cancelButtonTitle:@"Ok"
                                                      otherButtonTitles:nil];
        [alert show];

    }

}


-(void)pick
{
@try {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.navigationBar.tintColor = [UIColor blackColor];

    popOver = [[UIPopoverController alloc] initWithContentViewController:picker];
    [popOver presentPopoverFromRect:self.FileAddButton.bounds inView:self.FileAddButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    self.popOver = popOver;
}
@catch (NSException *exception) {
    appdelegate.methodNameString=@"pickFile";
    appdelegate.NSExceptionString=[NSString stringWithFormat:@"%@",exception.description];
    [self exception];

}
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

@try
{
    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
    {

        [picker dismissViewControllerAnimated:YES completion:nil];

        UIImage *fullImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];

        UIImage *thumbImage = [fullImage imageByScalingAndCroppingForSize:CGSizeMake(180,180)];
        self.detailItem.fullImage = fullImage;
        self.detailItem.thumbImage = thumbImage;

        NSData *dataObj = UIImagePNGRepresentation(thumbImage);
        base64String=[dataObj base64Encoding];

        NSDate *currentDateTime = [NSDate date];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"MMddyyyy_HHmmss"];
        NSString *dateInStringFormated = [dateFormatter stringFromDate:currentDateTime];

        fileName = [NSString stringWithFormat:@"IMG_%@.png",dateInStringFormated];

        [self Uploadfile];
    }
    else
    {
        //        [picker dismissViewControllerAnimated:YES completion:nil];

        [self.popOver dismissPopoverAnimated:true];

        UIImage *fullImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];


        UIImage *thumbImage = [fullImage imageByScalingAndCroppingForSize:CGSizeMake(180,180)];
        self.detailItem.fullImage = fullImage;
        self.detailItem.thumbImage = thumbImage;

        NSData *dataObj = UIImagePNGRepresentation(thumbImage);
        base64String=[dataObj base64Encoding];

        NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
        ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
        {
            ALAssetRepresentation *representation = [myasset defaultRepresentation];
            fileName = [representation filename];
            NSLog(@"fileName siva : %@",fileName);
            [self Uploadfile];

        };

        ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
        [assetslibrary assetForURL:imageURL
                       resultBlock:resultblock
                      failureBlock:nil];


    }
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];

}
@catch (NSException *exception)
{
    appdelegate.methodNameString=@"didFinishPickingMediaWithInfo";
    appdelegate.NSExceptionString=[NSString stringWithFormat:@"%@",exception.description];
    [self exception];
}
@finally
{

}

}

and i also tried with including this...我也试过包括这个......

- (BOOL)shouldAutorotate {
    return NO;
 }

just try setting interface orientation of your viewcontroller只需尝试设置视图控制器的界面方向

- (BOOL)shouldAutorotate {
    return YES;
 }

    - (NSUInteger) supportedInterfaceOrientations
    {
         //Because your app is only landscape, your view controller for the view in your
         // popover needs to support only landscape
         return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM