Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios8 处理不同宽度iDevice的最佳方法?_Ios8 - Fatal编程技术网

Ios8 处理不同宽度iDevice的最佳方法?

Ios8 处理不同宽度iDevice的最佳方法?,ios8,Ios8,我想知道是否有人可以提供一些见解,如何处理不同的设备大小时,在故事板设计 在进行工程视图之前,是否必须检查设备框架尺寸 谢谢。有两种方法可以解决这个问题。如果坚持使用框架,则需要在绘制视图之前检查框架大小。一种方法是在utils文件中编写一个方法来检查设备,如下所示: + (NSString *)getHardwareModel { AppDelegate_iPhone *appDelegate_iPhone = (AppDelegate_iPhone *) [[UIApplicatio

我想知道是否有人可以提供一些见解,如何处理不同的设备大小时,在故事板设计

在进行工程视图之前,是否必须检查设备框架尺寸


谢谢。

有两种方法可以解决这个问题。如果坚持使用框架,则需要在绘制视图之前检查框架大小。一种方法是在utils文件中编写一个方法来检查设备,如下所示:

+ (NSString *)getHardwareModel {
    AppDelegate_iPhone *appDelegate_iPhone = (AppDelegate_iPhone *) [[UIApplication sharedApplication] delegate];
    size_t size;
    // get the size of the returned device name
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    // allocate the space to store name
    char *machine = (char*)malloc(size);
    // get the device name
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    // place the name into a NSString
    NSString *platform = [NSString stringWithCString:machine encoding: NSUTF8StringEncoding];
    free(machine);

    appDelegate_iPhone.hardwareModel = platform;

    return platform;
}
一旦我们得到我们正在使用的设备,我们就可以相应地设置帧。因此,如果我想检查iPhone6设备,我会在setFrameSize方法中执行以下操作:

NSString *hardwareVersion = [Utils getHardwareModel];
    NSString *target=@"x86_64";
    NSString *deviceTarget=@"iPhone7,1";
    NSRange range =[hardwareVersion rangeOfString:target ];
    NSRange deviceRange =[hardwareVersion rangeOfString:deviceTarget ];
    NSLog(@"device=%@",hardwareVersion);

    // Setting the frame size for the progress bar


        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
            if (range.location!=NSNotFound ||deviceRange.location!=NSNotFound) {
                float frameSize =  self.view.frame.size.width;
                NSLog(@"Frame width===%f", frameSize);
                self.view.frame = CGRectMake(0, 0, 480, 85);
            }
另一种避免所有这些的方法是使用autolayout并根据不同的屏幕大小设置约束