2013-11-15 3 views
0

Я новичок в программировании на iOS. Я сделал приложение для iPhone retina 4-inch. Теперь я хочу, чтобы настроить мой код для того, чтобы работать на iPhone сетчатки глаза 3.5 дюйма и iPhone 5.выравнивание для разных устройств ios

Я попытался создать, если запрос для self.view.frame.size.width и self.view.frame.size.height, но я получаю «Не назначаемой» ошибка.

Может ли кто-нибудь сказать мне, как указать условия для оптимальной настройки рабочего пространства на всех устройствах? Если возможно, дайте мне точный размер экрана всех этих устройств.

ответ

0

сравнить размер экрана включить этот макрос и использовать его в любом месте необходимо

#define isPhone5 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568) 


если вы хотите сравнить размеры экрана только затем уменьшить выше макрос


#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE 


Например, в файле .m

#import "ViewController.h" 

    #define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE //hear u put the macro and use it anywhere in this file 

@interface ViewController()<FootballPlayerDelegate>//confirms to this delegate 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    if(isiPhone5) 
    { 
     NSLog(@"I am 4inch screen"); 

    } 
    else 
    { 
     NSLog(@"I am 3.5inch screen"); 
    } 
    // Do any additional setup after loading the view, typically from a nib. 
} 


+0

извините, но я новичок в ios и не знал, что нужно положить и как использовать свой макрос. Я создал кнопки в viewdidload, поэтому просто хочу изменить размер моих кнопок в соответствии с другим устройством ios. –

+0

@yourwish я отредактировал код, проверяю его :) –

0

Попробуйте в файле .M:

-(void)viewWillAppear:(BOOL)animated 
{ 

    [self willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:1.0]; 

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

    if(orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft) 

    { 
     [self setFrameForLeftAndRightOrientation]; 
    } 

    else if(orientation == UIInterfaceOrientationPortrait) 

    { 
     [self setFrameForPortraitAndUpsideDownOrientation]; 
    } 
} 

- (void)willAnimateRotationToInterfaceOrientation: 
(UIInterfaceOrientation)toInterfaceOrientation 
             duration:(NSTimeInterval)duration 
{ 
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 

    { 
     [self setFrameForLeftAndRightOrientation]; 
    } 

    else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) 

    { 
     [self setFrameForPortraitAndUpsideDownOrientation]; 
    } 


} 
-(void)setFrameForLeftAndRightOrientation 
{ 

    if(IS_IPAD) 

    { 
     //Write here code for iPad (Landscape mode) 
    } 

    else if(IS_IPHONE) 
    { 

     if ([[UIScreen mainScreen] bounds].size.height == 568) 
     { 
      //Write code here for iPhone 5 (Landscape mode) 
     } 
     else 
     { 
      //Write code here for iPhone(3.5 inch) (Landscape mode) 
     } 
    } 
} 

-(void)setFrameForPortraitAndUpsideDownOrientation 
{ 
    if(IS_IPAD) 
    { 

    } 
    else if(IS_IPHONE) 
    { 

     if ([[UIScreen mainScreen] bounds].size.height == 568) 
     { 

     } 
     else 
     { 

     } 
    } 

} 
+0

THanx man. Это моя проблема. –

+0

My Pleasure .... –

+0

@yourwish, если это решит вашу проблему. Положите галочку на этот ответ. Потому что он решил мой тоже ^^ –

0
#define IS_IPHONE_SIMULATOR ([[[UIDevice currentDevice]model] isEqualToString : @"iPhone  Simulator"]) 
    #define IS_IPHONE ([[[UIDevice currentDevice]model] isEqualToString : @"iPhone"]) 
    #define IS_IPOD_TOUCH ([[[UIDevice currentDevice]model] isEqualToString : @"iPod Touch"]) 
    #define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f 
    #define ITS_IPHONE5 (IS_HEIGHT_GTE_568) 



if (ITS_IPHONE5) 

{ 

} 

else 

{ 

} 
0

использовать этот код в проект-Prefix.pch файл в папку поддержки.

#define IS_IPHONE_SIMULATOR ([[[UIDevice currentDevice]model] 
      isEqualToString : @"iPhone  Simulator"]) 
    #define IS_IPHONE ([[[UIDevice currentDevice]model] isEqualToString : @"iPhone"]) 
    #define IS_IPOD_TOUCH ([[[UIDevice currentDevice]model] isEqualToString : @"iPod  Touch"]) 
    #define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f 
    #define ITS_IPHONE5 (IS_HEIGHT_GTE_568) 

Копирование и мимо этого Кодекса После этого в вашем .m файл мимо первого кода я даю вам ... Dont нужно писать размер на viewdidload писать только в этих койках

 if (IS_IPAD) 
      { 

      } 
      else if(IS_IPHONE) 
      { 

       if ([[UIScreen mainScreen] bounds].size.height == 568) 
       { 

       } 
     else 
       { 

       } 
      } 
2
You look at the device's screen size (in points) and from that surmise if it's an iPad or iPhone etc., and then use hard-coded values for the screen sizes. 

Here's some code to get the screen size: 

CGRect screenRect = [[UIScreen mainScreen] bounds]; 
CGFloat screenWidth = screenRect.size.width; 
CGFloat screenHeight = screenRect.size.height; 

Be aware that width and height might be swapped, depending on device orientation. 
Смежные вопросы