2

我的代码在最后一行给出[__NSMallocBlock__ size]错误。我尝试使用此类来实现自定义捏合以裁剪图像,但“self.cropView.image =self.image;”行似乎有一些问题。

@interface PECropViewController () <UIActionSheetDelegate>
@property (nonatomic) PECropView *cropView;
@property (nonatomic) UIActionSheet *actionSheet;
@end
@implementation PECropViewController
+ (NSBundle *)bundle
{
    static NSBundle *bundle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"PEPhotoCropEditor" withExtension:@"bundle"];
        bundle = [[NSBundle alloc] initWithURL:bundleURL];
    });
    return bundle;
}

static inline NSString *PELocalizedString(NSString *key, NSString *comment)
{
    return [[PECropViewController bundle] localizedStringForKey:key value:nil table:@"Localizable"];
}

- (void)loadView
{
    UIView *contentView = [[UIView alloc] init];
    contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    contentView.backgroundColor = [UIColor blackColor];
    self.view = contentView;
    self.cropView = [[PECropView alloc] initWithFrame:contentView.bounds];
    [contentView addSubview:self.cropView];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                 target:self
                 action:@selector(cancel:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                 target:self
                 action:@selector(done:)];
    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                 target:nil
                 action:nil];
    UIBarButtonItem *constrainButton = [[UIBarButtonItem alloc] initWithTitle:PELocalizedString(@"Constrain", nil)
                                                                        style:UIBarButtonItemStyleBordered
                                                                       target:self
                                                                       action:@selector(constrain:)];
    self.toolbarItems = @[flexibleSpace, constrainButton, flexibleSpace];
    self.navigationController.toolbarHidden = NO;
    self.cropView.image =self.image;
}
4

1 回答 1

0

为图像分配的内存存在问题。self.image 中的图像未设置或未正确分配内存。您可以为图像分配内存:

UIImage* image = [[UIImage alloc] init];

它在类似的情况下帮助了我。

于 2016-01-26T10:35:09.447 回答