所以我非常接近完成我的小项目,并且我正在努力确保我的应用程序与 iPhone 3 和 4 兼容......但这真的让我很难过。我正在使用hm50前段时间发布的开源CCPickerview代码(http://www.cocos2d-iphone.org/forum/topic/10160)。它适用于 iPhone 4,但不适用于 iPhone 3 模拟器。我认为问题出在实施中的某个地方。当我错误地将 -hd 标签留在图像上时,我可以看到发生了什么。看起来图像在非视网膜模式下被切成两半,我不能说我是一个足以确定原因的专家。
-(void)makePages {
CCSprite *overlay = [CCSprite spriteWithFile:@"overlay-hd.png"];
CGSize s = CGSizeMake(overlay.contentSize.width, overlay.contentSize.height);
self.contentSize = s;
CCLayerColor *backLayer = [CCLayerColor layerWithColor:(ccColor4B){248,250,251,255} width:self.contentSize.width height:self.contentSize.height];
backLayer.position = ccp(-self.contentSize.width/2, -self.contentSize.height/2);
[self addChild:backLayer];
self.baseLayer = [CCLayerColor layerWithColor:(ccColor4B){150,150,150,0} width:s.width height:imgSize.height * numPages];
for (int i=0; i < [arrayPages count]; i++) {
CCNode* n = [arrayPages objectAtIndex:i];
n.position = ccp(s.width/2, s.height/2 + i * (imgSize.height + padding));
[baseLayer addChild:n];
}
baseLayer.position = ccp(-s.width/2, -s.height/2 - s.height * currentPage);
[self addChild:baseLayer];
overlay.position = ccp(0, 0);
//overlay.opacity = 0;
[self addChild:overlay];
rect = CGRectMake(self.position.x - s.width/2, self.position.y - s.height/2, s.width, s.height);
[self moveToPagePosition];
}
- (void) visit
{
if (!self.visible)
return;
glPushMatrix();
glEnable(GL_SCISSOR_TEST);
CGSize size = [[CCDirector sharedDirector] winSize];
CGRect scissorRect = rect;
ccDeviceOrientation orientation = [[CCDirector sharedDirector] deviceOrientation];
switch (orientation)
{
case kCCDeviceOrientationPortrait:
break;
case kCCDeviceOrientationPortraitUpsideDown:
scissorRect.origin.x = size.width-scissorRect.size.width-scissorRect.origin.x;
scissorRect.origin.y = size.height-scissorRect.size.height-scissorRect.origin.y;
break;
case kCCDeviceOrientationLandscapeLeft:
{
float tmp = scissorRect.origin.x;
scissorRect.origin.x = scissorRect.origin.y;
scissorRect.origin.y = size.width-scissorRect.size.width-tmp;
tmp = scissorRect.size.width;
scissorRect.size.width = scissorRect.size.height;
scissorRect.size.height = tmp;
}
break;
case kCCDeviceOrientationLandscapeRight:
{
float tmp = scissorRect.origin.y;
scissorRect.origin.y = scissorRect.origin.x;
scissorRect.origin.x = size.height-scissorRect.size.height-tmp;
tmp = scissorRect.size.width;
scissorRect.size.width = scissorRect.size.height;
scissorRect.size.height = tmp;
}
break;
}
glScissor(scissorRect.origin.x*2, scissorRect.origin.y*2,
scissorRect.size.width*2, scissorRect.size.height*2);
[super visit];
glDisable(GL_SCISSOR_TEST);
glPopMatrix();
}
如果我将滚动条移到右边,它会显示更多,但我真的不希望它在那里。你们中的任何一位出色的objective-c大师都可以帮我解决这个问题吗?
编辑:
经过进一步调查,问题毫无疑问是:
rect = CGRectMake(self.position.x - s.width/2, self.position.y - s.height/2, s.width, s.height);
如果我成功了
rect = CGRectMake(self.position.x - s.width*2.05, self.position.y - s.height/1.48, self.contentSize.width*1.3, self.contentSize.height*.48);
它工作得很好......但我认为这个解决方案不是很优雅,它应该基于覆盖图片的大小。我不确定我在这里做错了什么。