Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone CGImageRef更改_Iphone_Ios_Xcode_Cocoa Touch_Cgimageref - Fatal编程技术网

Iphone CGImageRef更改

Iphone CGImageRef更改,iphone,ios,xcode,cocoa-touch,cgimageref,Iphone,Ios,Xcode,Cocoa Touch,Cgimageref,在那里。如何从另一个ViewController更改CGImageRef 我有以下代码: #import "ScratchableView.h" @implementation ScratchableView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { //init with the scratchable gray image

在那里。如何从另一个ViewController更改CGImageRef

我有以下代码:

#import "ScratchableView.h"

@implementation ScratchableView

- (id)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {

      //init with the scratchable gray image




           scratchable = [UIImage imageNamed:@"image.jpg"].CGImage;

            width = CGImageGetWidth(scratchable);
    height = CGImageGetHeight(scratchable);

    self.opaque = NO;
    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();

    CFMutableDataRef pixels = CFDataCreateMutable( NULL , width * height );
    alphaPixels = CGBitmapContextCreate( CFDataGetMutableBytePtr( pixels ) , width , height , 8 , width , colorspace , kCGImageAlphaNone );
    provider = CGDataProviderCreateWithCFData(pixels);

    CGContextSetFillColorWithColor(alphaPixels, [UIColor blackColor].CGColor);
    CGContextFillRect(alphaPixels, frame);

    CGContextSetStrokeColorWithColor(alphaPixels, [UIColor whiteColor].CGColor);
    CGContextSetLineWidth(alphaPixels, 30.0);
    CGContextSetLineCap(alphaPixels, kCGLineCapSquare);

    CGImageRef mask = CGImageMaskCreate(width, height, 8, 8, width, provider, nil, NO);
    scratched = CGImageCreateWithMask(scratchable, mask);



    CGImageRelease(mask);
    CGColorSpaceRelease(colorspace);

    }
    return self;
}
现在,我想从另一个视图控制器将image.jpg更改为image2.jpg。求求你,帮帮我,我怎么做


我尝试使用app delegate和nsstrings,但没有成功。我是初学者。

让一个对象影响另一个对象的两种常见方法是提供可设置的公共属性,或者在类上提供方法+参数。在这两种情况下,想要进行更改的对象都需要某种方式来访问第二个对象。通常的方法是在UINavigation ViewController数组中找到它,或者通过tabBarController,通过appDelegate,或者第二个类是singleton,可以通过向class对象请求引用来找到它

当您解决此问题时,调用类将执行类似于发送具有此签名的消息的操作:

- (BOOL)updateImage:(CGImageRef)theNewImage

ScratchableView
是如何声明的?它从何而来?如何显示
image.jpg
?-(void)awakeFromNib{//添加一个可刮式视图,其中可刮式图像scratchableView=[[scratchableView alloc]initWithFrame:self.frame];[self-addSubview:scratchableView];backimg=[NSString stringWithFormat:@“backgr1.jpg”];//在可擦写图像下添加另一个图像。UIImageView*背景=[[UIImageView alloc]initWithImage:[UIImageName:backimg]];[self-addSubview:background];[self-bringSubviewToFront:scratchableView];}我从github获得了CGScratch项目,我想滑动或摇动以更改这两个图像,你能帮帮我吗。。