CALayer *featureLayer = nil;
[featureLayer setContents:(id)[square CGImage]];
我需要从数组图像内部更改触摸时的“正方形”。
- (void)viewDidLoad
{
[super viewDidLoad];
images = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"ic copy2"],
[UIImage imageNamed:@"bubble 1"],
[UIImage imageNamed:@"bubble 2"],
[UIImage imageNamed:@"bubble 3"],
[UIImage imageNamed:@"bubble 4"],
nil];
square=[images objectAtIndex:0];
//some code....}
这是在触摸事件上更改图像的方法。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"'Touches Began");
if ([touch view] == previewView) {
square = [images objectAtIndex:1];
NSLog(@"Image touched and changed");
}
currentImage++;
NSLog(@"Touch Count = %d", currentImage);
if (currentImage == [images count])
currentImage = 0;
square= [images objectAtIndex:currentImage];
}
由于 Setcontents 制作图像的静态副本,因此图像在 uiview 中不会改变。有什么方法可以从图像数组中更改触摸时添加内容的图像。?