是否可以在UIView动画进行过程中取消动画?或者我是否必须降至CA级别?
即我已经完成了这样的事情(也可能设置一个结束动画动作):
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
// other animation properties
// set view properties
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
但是在动画完成之前我得到动画结束事件,我想取消它(剪短它).这可能吗?谷歌搜索周围发现一些人问同样的问题没有答案 - 一两个人推测它不能完成.
我的简单目标是淡化隐藏和显示功能的动画.
Button.hidden = YES;
Run Code Online (Sandbox Code Playgroud)
很简单.但是,是否有可能让它淡出而不仅仅是消失?这样看起来相当不专业.
当使用时解除模态视图控制器时dismissViewController,可以选择提供完成块.是否有相似的等价物popViewController?
完成论证非常方便.例如,我可以使用它来阻止从tableview中删除一行,直到模态关闭屏幕,让用户看到行动画.从推出的视图控制器返回时,我想要同样的机会.
我已经尝试放置popViewController一个UIView动画块,我可以访问完成块.但是,这会对弹出的视图产生一些不必要的副作用.
如果没有这样的方法,有什么办法吗?
我正在寻找一种动画绘制圆圈的方法.我已经能够创建圆圈,但它将所有这些组合在一起.
这是我的CircleView班级:
import UIKit
class CircleView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = UIColor.clearColor()
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func drawRect(rect: CGRect) {
// Get the Graphics Context
var context = UIGraphicsGetCurrentContext();
// Set the circle outerline-width
CGContextSetLineWidth(context, 5.0);
// Set the circle outerline-colour
UIColor.redColor().set()
// Create Circle
CGContextAddArc(context, (frame.size.width)/2, frame.size.height/2, (frame.size.width - 10)/2, 0.0, CGFloat(M_PI * 2.0), 1)
// Draw
CGContextStrokePath(context);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我如何将其添加到视图控制器中的视图层次结构中:
func addCircleView() …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我需要从UINavigationController的堆栈中删除一个视图,并将其替换为另一个.情况是第一个视图创建一个可编辑的项目,然后用该项目的编辑器替换它自己.当我在第一个视图中执行明显的解决方案时:
MyEditViewController *mevc = [[MYEditViewController alloc] initWithGizmo: gizmo];
[self retain];
[self.navigationController popViewControllerAnimated: NO];
[self.navigationController pushViewController: mevc animated: YES];
[self release];
Run Code Online (Sandbox Code Playgroud)
我的行为非常奇怪.通常编辑器视图会出现,但如果我尝试使用导航栏上的后退按钮,我会得到额外的屏幕,有些空白,有些只是搞砸了.标题也变得随机.就像导航堆栈完全被冲洗一样.
什么是解决这个问题的更好方法?
谢谢,马特
我有一个iOS 7应用程序,我在这里设置一个自定义后退按钮,如下所示:
UIImage *backButtonImage = [UIImage imageNamed:@"back-button"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, 20, 20);
[backButton addTarget:self
action:@selector(popViewController)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
viewController.navigationItem.leftBarButtonItem = backBarButtonItem;
Run Code Online (Sandbox Code Playgroud)
但是这会禁用iOS 7"从左向右滑动"手势以导航到之前的控制器.有谁知道如何设置自定义按钮并仍然启用此手势?
编辑:我试图设置viewController.navigationItem.backBarButtonItem,但这似乎并没有显示我的自定义图像.
uinavigationcontroller uibarbuttonitem uiviewanimation ios ios7
我正在努力用CALayer概念化动画而不是UIView自己的动画方法.把" 核心动画 "扔进去,好吧,也许有人可以从高层次上清楚地表达这些概念,这样我就可以更好地想象发生了什么,以及为什么我想把UIView动画(我现在很熟悉)迁移到CALayer iPhone上的动画.Cocoa-Touch中的每个视图都会自动获取一个图层.而且,似乎你可以为一个和/或另一个制作动画?!?甚至将它们混合在一起?!?但为什么?线路在哪里?每个人的赞成/赞成是什么?
核心动画编程指南立即跳转到层和计时类,我认为需要退一步,理解为什么这些不同的部分存在以及如何相互关联.
我试图动画的变化cornerRadius一个的UIView实例layer,但的变化cornerRadius立即生效.
这是代码:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
view.layer.masksToBounds = YES;
view.layer.cornerRadius = 10.0;
[UIView animateWithDuration:1.0 animations:^{
[view.layer.cornerRadius = 0.0;
}];
Run Code Online (Sandbox Code Playgroud)
谢谢大家给我任何提示.
编辑:我设法Core Animation使用a 来动画这个属性CABasicAnimation.
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSNumber numberWithFloat:10.0f];
animation.toValue = [NSNumber numberWithFloat:0.0f];
animation.duration = 1.0;
[viewToAnimate.layer addAnimation:animation forKey:@"cornerRadius"];
[animation.layer setCornerRadius:0.0];
Run Code Online (Sandbox Code Playgroud) 我试图用标签栏交换到另一个根视图控制器; 通过app委托,我想添加过渡动画.默认情况下,它只显示没有任何动画的视图.
let tabBar = self.instantiateViewController(storyBoard: "Main", viewControllerID: "MainTabbar")
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window = UIWindow(frame: UIScreen.main.bounds)
appDelegate.window?.rootViewController = tabBar
appDelegate.window?.makeKeyAndVisible()
Run Code Online (Sandbox Code Playgroud)
这就是我交换到另一个rootview控制器的方式.
我有一个带有GIF横幅的字符串,我需要将其放入应用程序.
我的代码:
func showAdd(){
Request.get("http://www.kyst.no/api/?apiMode=advertisement&lang=no", { (error: NSError?, data: NSData, text: NSString?) -> () in
let jsonResult: Dictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as Dictionary<String, AnyObject>
var banner : NSString = jsonResult["advertisement"]!["banner"] as NSString
self.addViewImage.image = UIImage.animatedImageNamed(banner, duration: 1)
})
}
Run Code Online (Sandbox Code Playgroud)
但没有任何反应.请帮忙.
uiviewanimation ×10
ios ×6
swift ×3
cocoa-touch ×2
uiview ×2
caanimation ×1
calayer ×1
cornerradius ×1
drawrect ×1
geometry ×1
ios7 ×1
iphone ×1
objective-c ×1
progress ×1
rootview ×1
swift3 ×1
uiimageview ×1
xcode ×1