我让我的窗口自动显示到可见屏幕。该代码没有问题。
但问题在于我需要将ImageView添加到窗口中,当然它们也应该能够调整大小。
创建ImageViews并使窗口适合当前可见
的代码- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
int x,y;
NSInteger rowCounter,gapX,gapY;
rowNumber=5;
rowCounter=0;
gapX=0;
gapY=0;
personNumber=10;
startX=20;
startY=20;
NSRect rect;
NSSize size;
NSScreen *scren=[NSScreen mainScreen];
rect=scren.visibleFrame;
y=rect.size.height;
x=rect.size.width;
NSLog(@"%s%s%d%s%d","screen"," y size=",y," x size=",x);
y=window.frame.size.height;
x=window.frame.size.width;
NSLog(@"%s%s%d%s%d"," window"," y size=",y," x size=",x);
timer1 =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(resizeWindow1) userInfo:nil repeats:YES];
rahmen=[[NSMutableArray alloc] initWithCapacity:25];
NSPoint p;
y=rect.size.height;
x=rect.size.width;
size.height=y;
size.width=x;
p.x= rect.origin.x;
p.y= rect.origin.y+y;
[window setContentSize:size];
[window setFrameTopLeftPoint:p];
width =x-(20*(personNumber/2));
width=(width/(personNumber/2))-(20/(personNumber/2));
NSLog(@"%s%ld","\n width: ",(long)width);
high= y-(20*rowNumber);
high=high/rowNumber-(20/rowNumber);
NSLog(@"%s%ld","\n high: ",(long)high);
for (indexRahmen=0; indexRahmen<25; ) {
if (indexRahmen>0 && indexRahmen%(personNumber/2)==0) {
rowCounter=rowCounter+1;
gapX=0;
gapY=gapY+1;
}
else if (indexRahmen%(personNumber/2)!=0){
gapX=gapX+1;
}
if (rowCounter==rowNumber) {
rowCounterr=rowNumber-1;
gapY=gapY-1;
}
rect=NSMakeRect(startX+(width*(indexRahmen%(personNumber/2)))+(gapX*20),(startY+(rowCounter*high)+(gapY*20)),width, high);
NSImageView *imageView=[[NSImageView alloc] initWithFrame:rect];
imageView.image = [NSImage imageNamed:@"umrandung.png"];
[rahmen insertObject:imageView atIndex:indexRahmen];
[window1view.self addSubview:imageView];
NSLog(@"%s%ld","\n IndexZahl: ",(long)indexRahmen);
indexRahmen=indexRahmen+1;
}
}
timer1调用的调整大小操作几乎相同,只是:
NSImageView *imageView= [rahmen objectAtIndex:indexRahmen];
imageView.frame= rect;
imageView.image = [NSImage imageNamed:@"umrandung.png"];
[rahmen insertObject:imageView atIndex:indexRahmen];
并且imageView未添加到window1view的子视图
并且确实发生的奇怪事情是1. NSImageView消失但是当我检查坐标时它们在正确的位置,所以我不知道为什么它会消失。
答案 0 :(得分:0)
我发现自己如何解决它。
我用而不是用:
创建ImageView[rahmen objectAtIndex:indexRahmen];
我用过:
for (NSImageView* ImageView in rahmen)
并且它可以正常使用。
可悲的是,我不知道它与其他方法消失的原因