iOS open source project: DYNavigationController
8291 단어 controller
HTTPS://GitHub.com/Dayang/D Y navigation controller
First initialize DYNavigationController with the previous follower view
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
RootViewController *rootViewController = [[[RootViewController alloc] init] autorelease];
DYNavigationController *navigationController = [[[DYNavigationController alloc]
initWithRootViewController:rootViewController] autorelease];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
This method defines the gesture operation of swiping left and right- (void)setUpGestureRecognizers:(UIViewController *)viewController {
// Swipe right: pop the current view and go back one level
UISwipeGestureRecognizer *rightSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(popCurrentViewOut:)];
rightSwipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
[viewController.view addGestureRecognizer:rightSwipeGesture];
[rightSwipeGesture release];
// Swipe left: push a new view
UISwipeGestureRecognizer *leftSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(pushNewViewIn:)];
leftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[viewController.view addGestureRecognizer:leftSwipeGesture];
[leftSwipeGesture release];
}
When swiping right, the current view is moved to the left of the screen and added to the navigation stack
- (void)pushViewController:(UIViewController *)viewController {
// Place the new view to the right next to the current view
viewController.view.frame = CGRectOffset(self.view.bounds, self.view.bounds.size.width, 0);
// Add the new view to our view hierarchy so that it displays on screen.
[self.view addSubview:viewController.view];
// Start animation
[UIView animateWithDuration:ANIMATION_DURATION delay:ANIMATION_DELAY options:UIViewAnimationCurveEaseInOut animations:^{
[self currentViewController].view.frame = CGRectOffset(self.view.bounds, -self.view.bounds.size.width, 0);
viewController.view.frame = self.view.bounds;
} completion:^(BOOL finished) {
if (finished) {
// Connect DYNavigationController to viewController if needed
[self setNavigatorIfNeeded:viewController];
// Set up gesture recognizer so that we can respond to swipes
[self setUpGestureRecognizers:viewController];
// Add the new controller to our viewControllerStack
[self.viewControllerStack addObject:viewController];
}
}];
}
Here, the class method animateWithDuration of UIView is used to realize the jump animation.When swiping left, the current view is removed from the navigation stack, and the view on the left is moved to the center of the screen to the right.
- (void)popViewController {
// Sanity check - We only pop when there are at least two viewControllers in the stack,
// otherwise there is nothing to pop
if (self.viewControllerStack.count < 2) return;
// Start animation
[UIView animateWithDuration:ANIMATION_DURATION delay:ANIMATION_DELAY options:UIViewAnimationCurveEaseInOut animations:^{
[self currentViewController].view.frame = CGRectOffset(self.view.bounds, self.view.bounds.size.width, 0);
[self previousViewController].view.frame = self.view.bounds;
} completion:^(BOOL finished) {
if (finished) {
// Tear down gesture recognizers
[self tearDownGestureRecognizers:[self currentViewController]];
// Remove current viewController.view from self.
[[self currentViewController].view removeFromSuperview];
// Remove current viewController from self.
[[self currentViewController] removeFromParentViewController];
// Remove current view controller from viewControllerStack
[self.viewControllerStack removeLastObject];
}
}];
}
The specific implementation of navigation is in DYNavigationController, DYNavigationControllerDelegate holds a property of DYNavigationController, and is synthesized in RootViewController, RootViewController implements DYNavigationControllerDelegate protocol, DetailViewController also implements DYNavigationControllerDelegate protocol, so DetailViewController can directly use this DYNavigationController reference to realize navigation Function.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Processing controlP5로 GUI 컨트롤러Processing에서 ControlP5 라이브러리를 사용하면 쉽게 GUI 컨트롤러를 만들 수 있습니다. 이번 자주 사용하는 슬라이더와 버튼에 대해 적어 둡니다. 향후 늘릴지도, 늘지 않을지도,라고 하는 곳. Pro...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.