iPad尺寸和坐标缩放到iPhone

时间:2017-03-09 10:57:36

标签: ios objective-c iphone ipad

我正在研究这个客观的c游戏应用程序,其中屏幕上有动物图片。

问题在于动物的大小和x / y在应用程序中是硬编码的,并且与iPad Air屏幕尺寸一起使用。我的问题是如何缩放它以在iPhone 7 plus上以相同的位置和大小显示?是否有公式来缩放尺寸和x / y坐标?

我在stackoverflow上寻找答案,并给出了分隔维度的答案,但是当我尝试将x / y坐标关闭时。

这是代码

-(void)viewDidLoad{
  [super viewDidLoad];
   NSString *sonidoPathBell1 = [[NSBundle mainBundle] pathForResource:@"bellTransition" ofType:@"aif"];
   NSURL *sonidoUrlBell1 = [[NSURL alloc] initFileURLWithPath:sonidoPathBell1];
   AudioServicesCreateSystemSoundID((CFURLRef)sonidoUrlBell1, &sonTrans);

   btnAnimales = [[NSMutableArray alloc] initWithCapacity:0];
   for(int i = 0; i < 20; i++){
    OBShapedButton *tempbtn = [[OBShapedButton alloc] init];
    [tempbtn setTag:i+1];
    opcion = [[NSUserDefaults standardUserDefaults] integerForKey:[NSString stringWithFormat:@"bluebaymobAmazingMixAndMatchObjeto%i",i + 1]];
    if (opcion == 0) {
        [tempbtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"btnAni%i.png",i+1]] forState:UIControlStateNormal];
    }else{
        [tempbtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"btnAni%iColor.png",i+1]] forState:UIControlStateNormal];
    }
    [tempbtn addTarget:self action:@selector(startPuzzle:) forControlEvents:UIControlEventTouchUpInside];
    CGRect cuadro = CGRectMake(0, 0, 0, 0);
    switch(i+1){
        case 1:
            cuadro = CGRectMake(131, 85, 95, 120);
            //cuadro = CGRectMake(94, 48, 65, 60);
            //37, 37, 30, 60
            break;
        case 2:
            cuadro = CGRectMake(52, 246, 147, 157);
            //cuadro = CGRectMake(15, 209, 117, 97);
            break;
        case 3:
            cuadro = CGRectMake(-5, 418, 166, 158);

            break;
        case 4:
            cuadro = CGRectMake(301, 64, 156, 151);

            break;
        case 5:
            cuadro = CGRectMake(214, 213, 129, 190);
            break;
        case 6:
            cuadro = CGRectMake(165, 384, 162, 169);
            break;
        case 7:
            cuadro = CGRectMake(204, 615, 139, 153);
            break;
        case 8:
            cuadro = CGRectMake(458, 115, 109, 90);
            break;
        case 9:
            cuadro = CGRectMake(367, 222, 207, 130);
            break;
        case 10:
            cuadro = CGRectMake(361, 344, 408, 276);
            break;
        case 11:
            cuadro = CGRectMake(387, 591, 234, 173);
            break;
        case 12:
            cuadro = CGRectMake(605, 104, 92, 131);
            break;
        case 13:
            cuadro = CGRectMake(671, 220, 152, 155);
            break;
        case 14:
            cuadro = CGRectMake(760, 450, 137, 174);
            break;
        case 15:
            cuadro = CGRectMake(701, 613, 101, 161);
            break;
        case 16:
            cuadro = CGRectMake(660, 26, 132, 88);
            break;
        case 17:
            cuadro = CGRectMake(828, 36, 112, 107);
            break;
        case 18:
            cuadro = CGRectMake(820, 288, 153, 157);
            break;
        case 19:
            cuadro = CGRectMake(909, 441, 115, 162);
            break;
        case 20:
            cuadro = CGRectMake(862, 629, 151, 135);
            break;
    }

    //1920 x1080 iphone 7plus
    //2048 x 1536 ipad
    //.9375
    //cuadro.origin.x = cuadro.origin.x * .9375;
    //cuadro.origin.y = cuadro.origin.y * .703125;
    //cuadro.origin.x = cuadro.origin.x - 37;
    //cuadro.origin.y = cuadro.origin.y - 37;
    //cuadro.size.width = cuadro.size.width - 30;
    //cuadro.size.height = cuadro.size.height - 60;
    tempbtn.frame = cuadro;
    [btnAnimales addObject:tempbtn];
    [self.view addSubview:[btnAnimales objectAtIndex:i]];
    tempbtn = nil;
}

}

0 个答案:

没有答案