1

我想知道是否可以将多个图像插入到objective-c中的“容器”中。

例如,如果我有一个前轮、后轮和汽车车身的图像。我可以将这些都放在一个容器中,以便当我移动或转换(缩放、旋转)容器时,里面的所有图像都会执行那个动作吗?同时,我可以让容器内的一个或多个图像执行动画。

我希望这很清楚,并且我已经正确解释了我正在尝试做的事情。

4

1 回答 1

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;

    }
于 2012-05-31T11:40:42.367 回答