该UIKeyboardAnimationCurveUserInfoKey有一个UIViewAnimationCurve值.如何将其转换为相应的UIViewAnimationOptions值以用于options参数+[UIView animateWithDuration:delay:options:animations:completion:]?
// UIView.h
typedef enum {
UIViewAnimationCurveEaseInOut, // slow at beginning and end
UIViewAnimationCurveEaseIn, // slow at beginning
UIViewAnimationCurveEaseOut, // slow at end
UIViewAnimationCurveLinear
} UIViewAnimationCurve;
// ...
enum {
// ...
UIViewAnimationOptionCurveEaseInOut = 0 << 16, // default
UIViewAnimationOptionCurveEaseIn = 1 << 16,
UIViewAnimationOptionCurveEaseOut = 2 << 16,
UIViewAnimationOptionCurveLinear = 3 << 16,
// ...
};
typedef NSUInteger UIViewAnimationOptions;
Run Code Online (Sandbox Code Playgroud)
显然,我可以使用switch语句创建一个简单的类别方法,如下所示:
// UIView+AnimationOptionsWithCurve.h
@interface UIView (AnimationOptionsWithCurve)
@end …Run Code Online (Sandbox Code Playgroud) 有没有办法判断UIView是否在动画中?当我在视图对象移动时打印出来时,我注意到有一个"动画"条目:
search bar should end editing: <UISearchBar: 0x2e6240; frame = (0 0; 320 88); text = ''; autoresize = W+BM; animations = { position=<CABasicAnimation: 0x6a69c40>; bounds=<CABasicAnimation: 0x6a6d4d0>; }; layer = <CALayer: 0x2e6e00>>
Run Code Online (Sandbox Code Playgroud)
当动画停止并且我打印视图时,"动画"条目现在消失了:
search bar should end editing: <UISearchBar: 0x2e6240; frame = (0 0; 320 88); text = ''; autoresize = W+BM; layer = <CALayer: 0x2e6e00>>
Run Code Online (Sandbox Code Playgroud) 我无法将图像快速旋转90度.我写了下面的代码,但有一个错误,不编译
func imageRotatedByDegrees(oldImage: UIImage, deg degrees: CGFloat) -> UIImage {
//Calculate the size of the rotated view's containing box for our drawing space
let rotatedViewBox: UIView = UIView(frame: CGRect(x: 0, y: 0, width: oldImage.size.width, height: oldImage.size.height))
let t: CGAffineTransform = CGAffineTransform(rotationAngle: degrees * CGFloat(M_PI / 180))
rotatedViewBox.transform = t
let rotatedSize: CGSize = rotatedViewBox.frame.size
//Create the bitmap context
UIGraphicsBeginImageContext(rotatedSize)
let bitmap: CGContext = UIGraphicsGetCurrentContext()!
//Move the origin to the middle of the image so we will rotate and scale around …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
CGRect r = [btn frame];
r.origin.y -= 40;
[btn setFrame: r];
}
completion:^(BOOL done){
if(done){
[UIView animateWithDuration:0.3
delay:1
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction
animations:^{
CGRect r = [btn frame];
r.origin.y += 40;
[btn setFrame: r];
}
completion:^(BOOL done){if(done) zombiePopping = 0; }];
}
}];
Run Code Online (Sandbox Code Playgroud)
问题是,即使我正在使用UIViewAnimationOptionAllowInteraction,按钮也不会在动画时响应触摸,这对我来说有点奇怪.
也许最好用Core Animation来完成这项工作?如果是的话,我该怎么做呢?
在我的设计示例中,我有以下单一视图:

如您所见,它包含一些简单的约束:
我想要实现的是让这个红色/粉红色的视图从顶部"进入".传统上,在一个无约束的世界中,我只是修改内部的框架UIView.animateWithDuration,但是我不确定我是如何在约束世界中做类似的.
为了重申我的问题,如何让我的视图从场景开始并使从顶部飞入的视图动画?
我已经考虑过制作垂直中心约束(并随后调用layoutIfNeeded),但它没有达到预期的效果.
谢谢你的帮助.
我已经阅读了有关segues的其他帖子但没有解决我的问题.
简单地说,我ViewController的订单就像一本书.我希望向后过渡(例如:从第9页到第8页)始终从左到右呈现(滑过).我希望从右到左呈现前向过渡(从第9页到第10页).
是的,如果您逐页翻页,我的导航控制器后退按钮(左上角)会显示如下内容.但是,如果从索引中跳转,则导航控制器上的后退功能会将您带回索引.
我的目标是,如果用户从索引跳到第9页(例如),然后向右滑动,它将向右滑动页面并显示第8页.一旦在第8页,如果他们向左轻弹页面将向左轻弹,他们将再次出现在第9页.
ViewController默认情况下,我所有人都是从右到左滑动.
示例:将其想象成一本书,如果我使用索引跳到第4章,然后向右滑动并从堆栈中弹出一个视图,我将回到索引.但是,如果您使用第394章第4章并向右滑动,则不希望返回索引!您想要转到第393页第3章的最后一页!因此导航堆栈对我没有帮助.
结束例子
详细信息:1.我在按钮上使用新的Xcode"Show"在ViewControllers之间切换.
我正在使用导航控制器,左上角的"后退"按钮功能.这使用导航堆栈并且工作正常.
但是我在底部有自己的自定义导航栏(后退按钮,主页按钮,索引按钮,前进按钮)和手势.这些是我想要的书籍功能.
快速编码.
使用Xcode 6.3
我读过有动画代码.我已经阅读了可以使用的深度程序转换.只是选择我想要从左边呈现的segue并轻松地反转动画,这似乎很疯狂.
谢谢!
尝试记录:
I tried DCDC's code:
UIView.transitionWithView(self.window!, duration: 0.5, options:.TransitionFlipFromLeft, animations: { () -> Void in
self.window!.rootViewController = mainVC
}, completion:nil)
Run Code Online (Sandbox Code Playgroud)
当我将DCDC的代码插入到IBAction我的后滑动中时,会返回此错误

如何在动画块中设置UIViewAnimationOptionsto :.RepeatUIView
UIView.animateWithDuration(0.2, delay:0.2 , options: UIViewAnimationOptions, animations: (() -> Void), completion: (Bool) -> Void)?)
Run Code Online (Sandbox Code Playgroud) 我的设置有问题UIViewAnimationOptionAutoReverse.这是我的代码.
CALayer *aniLayer = act.viewToChange.layer;
[UIView animateWithDuration:2.0 delay:1.0 options:(UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse) animations:^{
viewToAnimate.frame = GCRectMake(1,1,100,100);
[aniLayer setValue:[NSNumber numberWithFloat:degreesToRadians(34)] forKeyPath:@"transform.rotation"];
} completion:nil ];
Run Code Online (Sandbox Code Playgroud)
问题是,在动画反转后,视图会跳回到动画块中设置的帧.我希望视图成长并"取消"并停在原来的位置.
有没有编程两个连续动画的解决方案?
我希望能够在屏幕上和屏幕外移动子视图,就像在iPhone照片应用程序中构建的图像之间进行浏览一样,所以当我用手指放开时子视图的屏幕超过1/2,它必须屏幕上的动画,但它也必须支持滑动,因此如果滑动/平移速度足够高,它必须在屏幕上显示动画,即使屏幕可能小于1/2.
我的想法是使用UIPanGestureRecognizer,然后测试速度.这是有效的,但是如何基于视图的当前位置和平移速度为UIView的移动设置正确的动画持续时间,使其看起来平滑?如果我设置一个固定值,与我的手指滑动速度相比,动画开始变慢或变快.
uiview uigesturerecognizer uiviewanimation ios uipangesturerecognizer
如何使这个复杂的动画重复和自动反转?有没有办法添加选项UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat到这个动画序列?
[UIView animateWithDuration:1.0f animations:^{
someView.frame = someFrame1;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5f animations:^{
someView.frame = someFrame2;
} completion:nil];
}];
Run Code Online (Sandbox Code Playgroud) uiviewanimation ×10
ios ×9
uiview ×5
swift ×4
objective-c ×3
animation ×2
cocoa-touch ×2
xcode6 ×2
enums ×1
iphone ×1
segue ×1