2011-09-15 2 views
2

내가,아이폰 프로그래밍의 방향을 이해할 수 없습니까?

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)            name:UIDeviceOrientationDidChangeNotification object:nil]; 
    //Whenever the device orientation changes, orientationChanged will be called 

및 orientationChanged의 몸을 아래로있는 viewDidLoad에서 코드를 작성하고하는 것은 : 방법 나는이 방법의 행동을 이해 할 수없는 오전

 - (void)orientationChanged:(NSNotification *)notification 
    { 
     UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 

     NSLog(@"Method is Called"); 

     self.view.frame = CGRectMake(0, 0, 480, 320); 
     //self.view.superview.frame = CGRectMake(-50, -70, 800, 900); 

     //Based upon which orientation the device is in, update your View rotations. 
     //A simple view.transform = CGAffineTransformMakeRotation(whatever); will work well. 
    } 

을 따르고, 어떤 시체는 것을 말해 줄 수 이 두 라인이 어떤 작업을 수행하는지는 self.view.frame의 첫 번째 변화 프레임, 그리고 내가 주석 않았다 수퍼에 대한 두 번째.

사전 Saeen에서

덕분에 을

+0

은 왜 단순히이 – Narayana

+0

에 대한 NSNotificationCenter를 사용하여, 나는 내가 아래 코드는 그 코드를 시도하고 당신이 [자기 willAnimateRotationToInterfaceOrientation 같은 존재 오리엔테이션 viewWillAppear에서 메소드를 호출 할 수 있습니다 추가 –

+0

:-(스택에서 발견 기간 : 0.2]; – Narayana

답변

0

사용

덕분에이 작동 알림 센터의 insted 잘

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration 
    { 
     appDelegate.interface=interfaceOrientation; 
     [popoverController dismissPopoverAnimated:YES]; 
     if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     { 
     if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) 
     { 
      txt_description.font = [UIFont systemFontOfSize:17]; 
      appDelegate.screenWidth = 1024; 
      img_background.frame = CGRectMake(0, 0, 1024, 748); 
      img_background.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background_ipad_landscape" ofType:@"png"]]; 

      lbl_friendName.frame=CGRectMake(185, 58, 180, 30); 
      btn_friendName.frame=CGRectMake(390, 60, 436, 27); 
      [btn_friendName setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s14_ipad_landscape" ofType:@"png"]] forState:UIControlStateNormal]; 
      lbl_friendNameValue.frame=CGRectMake(399, 59, 300, 30); 
      lbl_date.frame=CGRectMake(185, 110, 180, 30); 
      btn_date.frame=CGRectMake(390, 110, 436, 27); 
      [btn_date setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s14_ipad_landscape" ofType:@"png"]] forState:UIControlStateNormal]; 
      lbl_dateValue.frame=CGRectMake(399, 109, 300, 30); 
      lbl_category.frame=CGRectMake(185, 160, 180, 30); 
      btn_category.frame=CGRectMake(390, 160, 436, 27); 
      [btn_category setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s14_ipad_landscape" ofType:@"png"]] forState:UIControlStateNormal]; 
      lbl_categoryValue.frame=CGRectMake(399, 159, 300, 30); 
      //btn_radio2.frame=CGRectMake(199, 128, 21, 21); 
      lbl_amount.frame=CGRectMake(185, 210, 180, 30); 
      txt_amount.frame=CGRectMake(390, 210, 436, 31); 
      lbl_currency.frame=CGRectMake(185, 260, 180, 30); 
      lbl_currencyValue.frame=CGRectMake(399, 258, 330, 30); 
      btn_currency.frame = CGRectMake(390, 260, 436, 27); 
      [btn_currency setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s14_ipad_landscape" ofType:@"png"]] forState:UIControlStateNormal]; 
      lbl_typeofCost.frame=CGRectMake(185, 310, 180, 30); 
      btn_radio1.frame = CGRectMake(390, 310, 21, 21); 
      lbl_allocate.frame = CGRectMake(420, 308, 180, 27); 
      btn_radio2.frame = CGRectMake(600, 310, 21, 21); 
      lbl_share.frame = CGRectMake(630, 308, 180, 27); 
      lbl_typeofCostValue.frame=CGRectMake(399, 348, 430, 30); 
      btn_typeofCost.frame = CGRectMake(390, 350, 436, 27); 
      [btn_typeofCost setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s14_ipad_landscape" ofType:@"png"]] forState:UIControlStateNormal]; 
      lbl_Description.frame=CGRectMake(185, 394, 180, 30); 
      img_inputbox.frame=CGRectMake(390, 400, 436, 61); 
      img_inputbox.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"input_box_s14_1_ipad_landscape" ofType:@"png"]]; 
      txt_description.frame=CGRectMake(395, 405, 436, 53); 
      lbl_placeholder.frame=CGRectMake(402, 405, 350, 21); 
      btn_save.frame=CGRectMake(430, 550, 128, 51); 
      scrollView.contentSize=CGSizeMake(self.view.frame.size.width, 800); 
      lbl_colon1.frame = CGRectMake(378, 58, 5, 30); 
      lbl_colon2.frame = CGRectMake(378, 108, 5, 30); 
      lbl_colon3.frame = CGRectMake(378, 158, 5, 30); 
      lbl_colon4.frame = CGRectMake(378, 208, 5, 30); 
      lbl_colon5.frame = CGRectMake(378, 258, 5, 30); 
      lbl_colon6.frame = CGRectMake(378, 304, 5, 30); 
      lbl_colon7.frame = CGRectMake(378, 392, 5, 30); 

     } 
     else 
     { 
      appDelegate.screenWidth=480; 
      [scrollView setContentSize:CGSizeMake(480, 440)]; 
      img_background.frame=CGRectMake(0, 0, 480,320); 
      img_topbar.frame=CGRectMake(0, 0, 480, 44); 
      img_background.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background_landscape" ofType:@"png"]]; 
      //lbl_head.frame=CGRectMake(160, 9, 159, 33); 

      lbl_friendName.frame=CGRectMake(13, 30, 110, 21); 
      btn_friendName.frame=CGRectMake(130, 27, 286, 27); 
      [btn_friendName setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"drop-down_s6_landscape" ofType:@"png"]] forState:0]; 


      lbl_date.frame=CGRectMake(13, 67, 95, 21); 
      btn_date.frame=CGRectMake(130, 64, 286, 27); 
      [btn_date setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"drop-down_s6_landscape" ofType:@"png"]] forState:0]; 

      lbl_category.frame=CGRectMake(13, 106, 95, 21); 
      btn_category.frame=CGRectMake(130, 102, 286, 27); 
      [btn_category setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"drop-down_s6_landscape" ofType:@"png"]] forState:0]; 
         //btn_radio2.frame=CGRectMake(199, 128, 21, 21); 
      lbl_amount.frame=CGRectMake(13, 143, 95, 21); 
      txt_amount.frame=CGRectMake(130, 140, 286, 31); 
      lbl_currency.frame=CGRectMake(13, 182, 95, 21); 
      btn_currency.frame = CGRectMake(130, 179, 286, 27); 
      [btn_currency setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"drop-down_s6_landscape" ofType:@"png"]] forState:0]; 

      lbl_typeofCost.frame=CGRectMake(13, 212, 95, 21); 
      btn_radio1.frame=CGRectMake(130, 212, 21, 21); 
      lbl_allocate.frame = CGRectMake(155, 212, 100, 21); 
      btn_radio2.frame = CGRectMake(275, 212, 21, 21); 
      lbl_share.frame = CGRectMake(310, 212, 80, 21); 
      btn_typeofCost.frame = CGRectMake(130, 240, 286, 27); 
      lbl_typeofCostValue.frame = CGRectMake(135, 242, 250, 21); 
      [btn_typeofCost setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"drop-down_s6_landscape" ofType:@"png"]] forState:UIControlStateNormal]; 
      //[btn_provideDate setImage:[UIImage imageNamed:@"dropdown_s5.png"] forState:UIControlStateNormal]; 
      lbl_Description.frame=CGRectMake(13, 276, 150, 21); 
      img_inputbox.frame=CGRectMake(130, 275, 286, 61); 
      img_inputbox.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"input_box_s42_landscape" ofType:@"png"]]; 
      txt_description.frame=CGRectMake(135, 281, 276, 45); 
      lbl_placeholder.frame=CGRectMake(142, 278, 200, 21); 
      btn_save.frame=CGRectMake(190, 345, 108, 41); 
      //btn_adv.frame=CGRectMake(0, 175, 480, 48); 
      lbl_colon1.frame = CGRectMake(119, 27, 5, 27); 
      lbl_colon2.frame = CGRectMake(119, 63, 5, 27); 
      lbl_colon3.frame = CGRectMake(119, 102, 5, 27); 
      lbl_colon4.frame = CGRectMake(119, 140, 5, 27); 
      lbl_colon5.frame = CGRectMake(119, 179, 5, 27); 
      lbl_colon6.frame = CGRectMake(119, 208, 5, 27); 
      lbl_colon7.frame = CGRectMake(119, 272, 5, 27); 
      [self displayProperFontSize]; 
      } 


     } 
     if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationPortrait) 
     { 

      if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) 
      { 
      txt_description.font = [UIFont systemFontOfSize:17]; 
      appDelegate.screenWidth=768; 
      img_background.frame = CGRectMake(0, 0, 768, 1004); 
      img_background.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background_ipad" ofType:@"png"]]; 

      lbl_friendName.frame=CGRectMake(105, 65, 180, 30); 
      btn_friendName.frame=CGRectMake(310, 67, 316, 27); 
      [btn_friendName setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6_ipad" ofType:@"png"]] forState:0]; 
      lbl_friendNameValue.frame=CGRectMake(318, 66, 280, 28); 
      lbl_date.frame=CGRectMake(105, 116, 180, 30); 
      btn_date.frame=CGRectMake(310, 116, 316, 27); 
      [btn_date setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6_ipad" ofType:@"png"]] forState:0]; 
      lbl_dateValue.frame=CGRectMake(315, 116, 278, 26); 
      lbl_category.frame=CGRectMake(105, 164, 180, 30); 
      btn_category.frame=CGRectMake(310, 166, 316, 27); 
      [btn_category setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6_ipad" ofType:@"png"]] forState:0]; 
      lbl_categoryValue.frame=CGRectMake(318, 167, 273, 26); 
      //btn_radio2.frame=CGRectMake(199, 128, 21, 21); 
      lbl_amount.frame=CGRectMake(105, 210, 180, 30); 
      txt_amount.frame=CGRectMake(310, 210, 316, 31); 
      lbl_currency.frame=CGRectMake(105, 260, 180, 30); 
      btn_currency.frame = CGRectMake(310, 258,316, 33); 
      lbl_currencyValue.frame=CGRectMake(316, 260, 310, 30); 
      [btn_currency setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6_ipad" ofType:@"png"]] forState:0]; 
      lbl_typeofCost.frame=CGRectMake(105, 310, 180, 30); 
      btn_radio1.frame=CGRectMake(310, 318, 21, 21); 
      lbl_allocate.frame = CGRectMake(340, 318, 100, 21); 
      btn_radio2.frame = CGRectMake(445, 318, 21, 21); 
      lbl_share.frame = CGRectMake(475, 318, 200, 21); 
      btn_typeofCost.frame = CGRectMake(310, 357,316, 33); 
      lbl_typeofCostValue.frame=CGRectMake(315, 359, 310, 30); 
      [btn_typeofCost setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6_ipad" ofType:@"png"]] forState:0]; 
      //[btn_provideDate setImage:[UIImage imageNamed:@"dropdown_s5.png"] forState:UIControlStateNormal]; 
      lbl_Description.frame=CGRectMake(105, 400, 180, 30); 
      img_inputbox.frame=CGRectMake(310, 410, 316, 61); 
      img_inputbox.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"input_box_s42_1_ipad" ofType:@"png"]]; 
      txt_description.frame=CGRectMake(316, 414, 310, 53); 
      lbl_placeholder.frame = CGRectMake(322, 414, 290, 21); 

      lbl_colon1.frame = CGRectMake(300, 65, 7, 30); 
      lbl_colon2.frame = CGRectMake(300, 114, 7, 30); 
      lbl_colon3.frame = CGRectMake(300, 164, 7, 30); 
      lbl_colon4.frame = CGRectMake(300, 209, 7, 30); 
      lbl_colon5.frame = CGRectMake(300, 260, 7, 30); 
      lbl_colon6.frame = CGRectMake(300, 313, 7, 30); 
      lbl_colon7.frame = CGRectMake(300, 402, 7, 30); 

      btn_save.frame=CGRectMake(300, 550, 128, 51); 
      } 
      else 
      { 
       appDelegate.screenWidth=320; 
       [scrollView setContentSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)]; 
       img_background.frame=CGRectMake(0, 0, 320,480); 
       img_background.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background" ofType:@"png"]]; 
       lbl_friendName.frame=CGRectMake(8, 16, 97, 34); 
       btn_friendName.frame=CGRectMake(114, 20, 196, 27); 
       [btn_friendName setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6" ofType:@"png"]] forState:UIControlStateNormal]; 

      lbl_friendNameValue.frame=CGRectMake(121, 20, 170, 28); 
      lbl_date.frame=CGRectMake(8, 59, 95, 21); 
      btn_date.frame=CGRectMake(114, 56, 196, 27); 
      [btn_date setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6" ofType:@"png"]] forState:UIControlStateNormal]; 
      lbl_dateValue.frame=CGRectMake(121, 53, 170, 34); 
      lbl_category.frame=CGRectMake(8, 96, 95, 21); 
      btn_category.frame=CGRectMake(114, 94, 196, 27); 
      [btn_category setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6" ofType:@"png"]] forState:UIControlStateNormal]; 
      lbl_categoryValue.frame=CGRectMake(120, 90, 166, 34); 
      //btn_radio2.frame=CGRectMake(199, 128, 21, 21); 
      lbl_amount.frame=CGRectMake(8, 136, 95, 21); 
      txt_amount.frame=CGRectMake(114, 131, 196, 31); 
      lbl_currency.frame=CGRectMake(8, 170, 95, 21); 

      btn_currency.frame =CGRectMake(114, 170, 196, 27); 
      [btn_currency setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6" ofType:@"png"]] forState:UIControlStateNormal]; 
      lbl_typeofCost.frame=CGRectMake(8, 205, 95, 21); 
      btn_radio1.frame=CGRectMake(114, 205, 21, 21); 
      lbl_allocate.frame = CGRectMake(140, 205, 80, 21); 
      btn_radio2.frame = CGRectMake(220, 205, 21, 21); 
      lbl_share.frame = CGRectMake(245, 199, 65, 34); 
      btn_typeofCost.frame = CGRectMake(114, 233, 196, 27); 
      lbl_typeofCostValue.frame = CGRectMake(119, 229, 170, 34); 
      [btn_typeofCost setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dropdown_s6" ofType:@"png"]] forState:UIControlStateNormal]; 
      //[btn_provideDate setImage:[UIImage imageNamed:@"dropdown_s5.png"] forState:UIControlStateNormal]; 
      lbl_Description.frame=CGRectMake(8, 265, 95, 21); 
      img_inputbox.frame=CGRectMake(114, 267, 196, 51); 
      img_inputbox.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"input_box_s16" ofType:@"png"]]; 
      txt_description.frame=CGRectMake(117, 274, 185, 37); 
      lbl_placeholder.frame = CGRectMake(124, 270, 160, 21); 
      btn_save.frame=CGRectMake(109, 326, 88, 41); 

      lbl_colon1.frame = CGRectMake(105, 20, 5, 27); 
      lbl_colon2.frame = CGRectMake(105, 55, 5, 27); 
      lbl_colon3.frame = CGRectMake(105, 94, 5, 27); 
      lbl_colon4.frame = CGRectMake(105, 133, 5, 27); 
      lbl_colon5.frame = CGRectMake(105, 168, 5, 27); 
      lbl_colon6.frame = CGRectMake(105, 201, 5, 27); 
      lbl_colon7.frame = CGRectMake(105, 262, 5, 27); 
      [self displayProperFontSize]; 
      } 
     } 
     [appDelegate adjustTab]; 


    } 
+0

내가이 용어를 검색하도록하겠습니다. 몇 줄의 비트 코드를 제공하면 고맙겠습니다. 애니메이션과 함께 오리엔테이션에 따라 레이블 CGRectMake를 변경하고 싶습니다. –

+0

Wao..it는 매우 간단하고 쉽게 보입니다. 디 – Nitish

0

당신이 장치를 회전 지금까지이 방법으로 프레임을 설정할 수 있습니다 때이 metod가 호출

 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration 
     { 
     if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     { 
      self.view.frame = CGRectMake(0, 0, 480, 300); 

     } 
     else 
     { 
      self.view.frame = CGRectMake(0, 0, 320, 460); 

     } 
    } 
2

방향에 따라보기를 관리 할 수 ​​있습니다. 내 대답 here을 확인하십시오. [UIApplication sharedApplication] .statusBarOrientation :

관련 문제