; 이렇게하면 메모리가 절약되고 렌더링이 쉬워집니다. 당신의 경우에도, 그러나, 당신은 또한 "모달"제시된보기 뒤의 창문을 보게됩니다.
자연스럽고 논리적 인 다음 단계는 하나의보기 컨트롤러보기를 가져 와서 다른보기 컨트롤러로 밀어 넣는 것입니다. 그러나, 당신이 발견 한대로, 이것은 문제가 있습니다. 새로 삽입 된 뷰가 뷰 계층에 안전하게 보관 되어도 안전하지만 새로운 뷰 컨트롤러는 그리 운이 좋지 않으므로 신속하게 할당이 취소됩니다. 따라서이 새로운보기가 컨트롤러에 연결하려고하면 EXC_BAD_ACCESS
이 표시되고 충돌이 발생합니다. 한 가지 해결 방법은 다시 원래보기 컨트롤러가 새로운보기 컨트롤러에 대한 강력한 참조를 유지하도록하는 것입니다. 그리고 이것은 ... 나쁘게 작동 할 수 있습니다. UIViewControllerHierarchyInconsistencyException
을 얻을 수있는 좋은 기회가 아직 있습니다.
물론 IB로 만든 작은보기를 추가하려는 경우보기 컨트롤러를 "File's Owner
"으로 사용할 필요가 없으며 xib
파일에서보기의 인스턴스를 만드는 많은 예가 있습니다 .
더 흥미로운 질문은 "사과는 어떻게 할 것인가?"입니다. Apple은 View Controller가 캡슐화 된 작업 단위 (UU)의 올바른 컨트롤러라고 일관되게 말합니다. 예를 들어, TWTweetComposeViewController
, 당신은 그것을 제시하고, 떠 다니는 것 같습니다. 어떻게?
이 작업을 수행하는 첫 번째 방법은 명확하지 않은 명확한 배경을 갖는 것입니다. 즉, 제공된보기 제어기가 나타나기 전에 화면 이미지를 작성하고 제시보기가 제거되기 전에이를 배경으로 설정하십시오. 그래서 (예를 들어 설명 따르도록) :
QuickSheetViewController.h
#import <UIKit/UIKit.h>
@interface QuickSheetViewController : UIViewController
- (IBAction)dismissButtonPressed:(id)sender;
@end
QuickSheetViewController.m
,691
QuickSheetViewController.xib을
#import "QuickSheetViewController.h" #import <QuartzCore/QuartzCore.h> @implementation QuickSheetViewController { UIImage *_backgroundImage; } -(void)renderAndSaveBackgroundImageFromVC:(UIViewController *)vc{ UIGraphicsBeginImageContext(vc.view.bounds.size); [vc.view.layer renderInContext:UIGraphicsGetCurrentContext()]; _backgroundImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; // save an image of the current view, and set our background to clear so we can see the slide-in. [self renderAndSaveBackgroundImageFromVC:self.presentingViewController]; self.view.backgroundColor = [UIColor clearColor]; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; // Time to use our saved background image. self.view.backgroundColor = [UIColor colorWithPatternImage:_backgroundImage]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; // Set our background to clear so we can see the slide-out. self.view.backgroundColor = [UIColor clearColor]; } - (IBAction)dismissButtonPressed:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end
이 예제의 대부분은 renderAndSaveBackgroundImageFromVC:
메서드를 사용합니다. 그래픽 컨텍스트를 작성하여 화면에 표시 할 뷰를 렌더링 한 다음 나중에 (viewDidAppear
)을 배경으로 사용합니다.
이제 단순히 좋아 사용 : 당신은 그냥 충분히 애니메이션이 발생하는 배경을 통해 볼 수
QuickSheetViewController *newVC = [[QuickSheetViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:newVC animated:YES completion:nil];
, 우리가 제시보기의 제거를 숨기기 위해 우리의 저장된 이미지를 사용합니다.
xib에서보기를 만들려면 다른보기 컨트롤러가 필요하지 않습니다. 단지보기 일 뿐인 xib을 가질 수 있습니다. 자,이 관점에서 무엇을하는지에 따라 자체 컨트롤러가 있어야 할 수도 있지만 필요하지는 않습니다. – rdelmar
보기가있는 xib입니다. 내 생각 엔이게 바로 나야. 이것이 어떻게 사용될 수 있는지 보여주는 튜토리얼이 있습니까? – Jim
자습서가 필요한 이유는 무엇입니까? "New File"을 선택하고 유형으로 "사용자 인터페이스"를 선택한 다음 "보기"를 선택하십시오. – rdelmar