如何在PopViewController上更改ViewController的动画方向

时间:2014-02-10 05:42:27

标签: ios uiviewcontroller uinavigationcontroller

是否可以更改ViewContoller Pop动画的方向 现在当我们推动VC时它显示动画从左到右和从右到左的流行音乐 但是我希望动画在Pop VC上从左到右滑动。

我曾尝试使用UIViewAnimationTransition

[UIView  beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];

但它没有我需要的动画,即从左到右滑动。这是我得到的动画

typedef enum {
   UIViewAnimationTransitionNone,
   UIViewAnimationTransitionFlipFromLeft,
   UIViewAnimationTransitionFlipFromRight,
   UIViewAnimationTransitionCurlUp,
   UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;

6 个答案:

答案 0 :(得分:5)

我使用了以下代码..

didFinishLaunchingWithOptions

中添加此内容
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //This line of code needed so you will not see the back window when its pop, match it with your app design.
    self.window.backgroundColor = [UIColor whiteColor];
    return YES;
}

POP 代码添加此代码的位置

CATransition* transition = [CATransition animation];
transition.duration = 0.4f;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:transition
                                            forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];

检查此GIF中的结果,
http://www.giphy.com/gifs/l2YSeBELE1phMEd5S

答案 1 :(得分:4)

干杯,这是swift 3.0~4.0版本。

<html>
<script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>

<input type="file" id="files" name="files[]" multiple />
<br/><br/>

<button id="getlink">Get Link</button>
<div id="output"></div>

<script>
 function handleSharedLink(evt) {

  $.ajax({     
     url: "https://api.dropboxapi.com/2/sharing/get_shared_links",

     headers:
        {
            "Authorization": "Bearer 1lzp0Ii5agAAAAAAAAAAJTVD-jRpVMcOfefVBzVkXOzM-W_LiFHSl7F9mgkd4bYk",
            "Content-Type": "application/json"
        },

    data:
        {
            "path": "TARCpace.apk"
        },
    success: function (data) {
            console.log(data);
    },
    error: function (data) {
            console.log(data);
    }
    r = requests.post(url, headers=headers, data=json.dumps(data))       
 })
}

  var output = document.getElementById('getlink').addEventListener('click', handleSharedLink, false);
  output.innerHTML = html(r);
</script>

</html> 

答案 2 :(得分:0)

您可以针对您的情况使用[UIView beginAnimations:]。根据需要setTransitionStyle。在Apple文档中查看可用UIViewAnimationTransitionStyle,请参阅此https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html

答案 3 :(得分:0)

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ActionBarNoShadowLight"
        android:fitsSystemWindows="true"
        app:elevation="0dp">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            android:fitsSystemWindows="true">
            <ImageView
                android:id="@+id/mainImage"
                android:layout_width="175dp"
                android:layout_height="175dp"
                android:layout_marginTop="50dp"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:scaleType="fitCenter"
                app:srcCompat="@drawable/ic_document"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />
            <android.support.v7.widget.Toolbar
                android:id="@+id/edit_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/BackgroundWhite"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:clipToPadding="false"
        android:scrollbars="none"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
            <ListView
                android:id="@+id/lstTask"
                android:layout_height="match_parent"
                android:layout_width="fill_parent"
                android:nestedScrollingEnabled="true"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:divider="@null"
                />
            <ImageView
                android:id="@+id/empty"
                android:layout_height="200dp"
                android:layout_width="200dp"
                android:layout_marginTop="50dp"
                android:scaleType="fitCenter"
                android:gravity="center"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                app:srcCompat="@drawable/bg_notasks" />
        </FrameLayout>
    </android.support.v4.widget.NestedScrollView>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_plus" />
</android.support.design.widget.CoordinatorLayout>

答案 4 :(得分:0)

你可以使用完成块来完成动画后的工作:

UIView.animate(withDuration: 0.75, animations: { () -> Void in

     UIView.setAnimationCurve(UIViewAnimationCurve.easeInOut)
     self.navigationController?.popViewController(animated: true)

})

答案 5 :(得分:-1)

 [UIView animateWithDuration:0.5f animations:^{
        self.myButton.transform = CGAffineTransformMakeScale(3, 3);
    } completion:^(BOOL finished){}];
    // for zoom out
    [UIView animateWithDuration:0.5f animations:^{

        self.myButton.transform = CGAffineTransformMakeScale(1, 1);
    }completion:^(BOOL finished){}];
    //View ANimation
    [UIView transitionWithView: self.navigationController.view
                      duration: 0.5
                       options: UIViewAnimationOptionTransitionCurlDown
                    animations: ^{

                        [self.navigationController popToRootViewControllerAnimated:YES];
                    }
                    completion: nil ];