我想知道是否可以在objective-c中将多个图像插入“容器”中。
例如,如果我有前轮,后轮和汽车车身的图像。我可以将这些全部放在一个容器中,这样当我移动或转换(缩放,旋转)容器时,里面的所有图像都会执行该操作吗?同时,我可以让容器内的一个或多个图像执行动画。
我希望这很清楚,我已经正确地解释了我想要做的事情。
答案 0 :(得分:0)
不确定容器,
但我有另一种方法,
为什么不制作一个自定义视图并将所有图像放在其中,并且可以在该视图上执行所有操作,
我发布了一些重要的方法,让我知道它是否适合您,我可能会分享更多细节
-(void)refreshSession{
// check all the added view, if needs to be displayed, then displayed them.
int visibleViews = [self getVisibleViews];
if(visibleViews == 0 ){
// if no more views to be displayed, then then let it not be visible,
[[self window] orderOut:self];
// do it will not be visible to anyone
return;
}
[self resize:visibleViews];
int viewsPerSide = [self getViewsPerRow];//ceil(sqrt(count));
int count = [pViewArray count];
int viewIndex=0;
NSInteger index = 0;
NSPoint curPoint = NSZeroPoint;
// Starting at the bottom left corner
// we should check all visible views
for ( int i = 0; i < count ; i++ ) {
// it will give only the view that needs to be shown
NSView *subview = [self getViewAtIndex:i];//(NSView *)[pViewArray objectAtIndex:i];
// is this visible
if(![self isViewVisibleAtIndex:i])
continue;
// is view visible
// if we have view to display then lets display it.
if(subview){
//[[[self window] contentView]setBackgroundColor:[NSColor blackColor]];
[[[self window]contentView] addSubview:subview ];
[self checkMask:viewIndex view:subview];
viewIndex++;
// let all the frame have same rect, regardless what are those
NSRect frame = NSMakeRect(curPoint.x, curPoint.y, BOXWIDTH, BOXHEIGHT);
// add them into the subview
NSRect newFrame = [self integralRect:frame];
[subview setFrame:newFrame];
[[subview animator] setFrame:[self integralRect:frame]];
[self setSubViewMask:subview ContentView:[[self window]contentView]];
// Now set the point
curPoint.x += BOXWIDTH + SEPARATION; // Stack them horizontally
if ((++index) % viewsPerSide == 0) { // And if we have enough on this row, move up to the next
curPoint.x = 0;
curPoint.y += BOXHEIGHT + SEPARATION;
}
}
}
NSArray *pSubViewsArray = [[[self window]contentView]subviews];
int arrayCount = [pSubViewsArray count];
debugLog<<"Array Count"<<arrayCount<<endl;
}