Trong bảng phân cảnh IOS, nếu bạn không muốn sử dụng điều hướng, thì bạn không thể sử dụng push segue. Sau đó, bạn có thể sử dụng phân đoạn phương thức hoặc phân đoạn tùy chỉnh. Trong segue modal, có bốn hiệu ứng chuyển tiếp:
- Bìa Dọc
- lật ngang
- Chữ thập Hòa tan
- phần Curl
Tuy nhiên, tất cả các hình ảnh động segue được xác định trước có thể không preform ngang trượt hoạt hình segue. Nếu bạn muốn sử dụng hiệu ứng trượt ngang, bạn phải sử dụng phân đoạn tùy chỉnh. Bạn cần ghi đè hàm này như sau:
- (void) perform
{
UIViewController *desViewController = (UIViewController *)self.destinationViewController;
UIView *srcView = [(UIViewController *)self.sourceViewController view];
UIView *desView = [desViewController view];
desView.transform = srcView.transform;
desView.bounds = srcView.bounds;
if(isLandscapeOrientation)
{
if(isDismiss)
{
desView.center = CGPointMake(srcView.center.x, srcView.center.y - srcView.frame.size.height);
}
else
{
desView.center = CGPointMake(srcView.center.x, srcView.center.y + srcView.frame.size.height);
}
}
else
{
if(isDismiss)
{
desView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
}
else
{
desView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
}
}
UIWindow *mainWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];
[mainWindow addSubview:desView];
// slide newView over oldView, then remove oldView
[UIView animateWithDuration:0.3
animations:^{
desView.center = CGPointMake(srcView.center.x, srcView.center.y);
if(isLandscapeOrientation)
{
if(isDismiss)
{
srcView.center = CGPointMake(srcView.center.x, srcView.center.y + srcView.frame.size.height);
}
else
{
srcView.center = CGPointMake(srcView.center.x, srcView.center.y - srcView.frame.size.height);
}
}
else
{
if(isDismiss)
{
srcView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
}
else
{
srcView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
}
}
}
completion:^(BOOL finished){
//[desView removeFromSuperview];
[self.sourceViewController presentModalViewController:desViewController animated:NO];
}];
}
Nếu bạn vẫn gặp sự cố, bạn có thể kiểm tra bài đăng này. Nó cũng có một đoạn video youtube để cho bạn thấy làm thế nào để thực hiện điều này segue tùy chỉnh:
Create Push Segue Animation Without UINavigation Controller
Làm thế nào để bạn che giấu các giao diện người dùng trong Storyboard? Và sau đó làm thế nào để bạn lập trình đẩy và bật ViewControllers? – Crashalot