스토리 보드의 UIButton에서 사용자 지정 세그리 (Modal Segue)를 어떻게 수행합니까?
-
13-11-2019 - |
문제
소스 장면에있는 버튼을 통해 대상 장면을 세그리팅하고 싶습니다.또한 ViewController 간의 전환 애니메이션을 제어하고 싶습니다 (오른쪽에서 왼쪽으로 2 개의보기를 애니메이션화하고 싶습니다).바꾸기 세그 슈를 통해 그렇게 할 수 있습니까?나는 교체 세그 슈와 푸시 세그 슈를 모두 시도하지만 세그 슈는 어떤 제안을 일어나지 않아야합니다. 어떻게해야합니까?감사!
해결책
Replace가 마스터 디테일 컨트롤러와 탐색 컨트롤러의 푸시 세그리에만 사용할 수 있기 때문에 Segue 및 Push Segue가 오도 된 것으로 나타났습니다.이 경우 대신 사용자 지정 세그리를 구현해야했습니다.UistoryBoardSegly를 하위 클래스하고 수행 Segue를 재정의해야합니다.
여기에 내 코드의 예가 있습니다 :
-(void)perform{
UIView *sourceView = [[self sourceViewController] view];
UIView *destinationView = [[self destinationViewController] view];
UIImageView *sourceImageView;
sourceImageView = [[UIImageView alloc]
initWithImage:[sourceView pw_imageSnapshot]];
// force the destination to be in landscape before screenshot
destinationView.frame = CGRectMake(0, 0, 1024, 748);
CGRect originalFrame = destinationView.frame;
CGRect offsetFrame = CGRectOffset(originalFrame, originalFrame.size.width, 0);
UIImageView *destinationImageView;
destinationImageView = [[UIImageView alloc]
initWithImage:[destinationView pw_imageSnapshot]];
destinationImageView.frame = offsetFrame;
[self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];
[destinationView addSubview:sourceImageView];
[destinationView addSubview:destinationImageView];
void (^animations)(void) = ^ {
[destinationImageView setFrame:originalFrame];
};
void (^completion)(BOOL) = ^(BOOL finished) {
if (finished) {
[sourceImageView removeFromSuperview];
[destinationImageView removeFromSuperview];
}
};
[UIView animateWithDuration:kAnimationDuration delay:.0 options:UIViewAnimationOptionCurveEaseOut animations:animations completion:completion];
}
.
주요 아이디어는 소스 및 대상 장면의 스크린 샷보기를 만드는 것입니다.대상 장면보기에 추가하고, 해당 두 뷰의 애니메이션을 제어하고 SourceViewController에서 PresentModalViewController 함수를 호출하고 애니메이션으로 완료하면 두 개의 스크린 샷보기를 제거합니다.
이 링크의 CH15에서 여기에 스크린 샷 유틸리티 기능을 구현하는 예제를 찾을 수 있습니다. http://learnipadprogramming.com/source-코드 /
제휴하지 않습니다 StackOverflow