我将一个较旧的应用程序移植到Xcode 7 beta,我的动画上出现错误:
无法使用类型'(Double,delay:Double,options:nil,animations :() - > _,completion:nil)的参数列表调用'animateWithDuration'
这是代码:
UIView.animateWithDuration(0.5, delay: 0.3, options: nil, animations: {
self.username.center.x += self.view.bounds.width
}, completion: nil)
Run Code Online (Sandbox Code Playgroud)
这适用于Xcode 6,所以我假设这是Swift中的更新.所以我的问题是:
什么是animateWithDuration的Swift 3语法?
正如标题所说,有没有办法为UIVisualEffectView的模糊半径设置动画?我在视图背后有一个动态背景,所以无法使用ImageEffects添加......据我所知,唯一可以做到这一点的是动画不透明度,但iOS抱怨说这样做打破了EffectView所以它肯定看起来好主意......任何帮助都会很高兴.
在objective-C中,我的动画位看起来像这样:
[UIView animateWithDuration:0.5 animations:^{
[[[_storedCells lastObject] topLayerView] setFrame:CGRectMake(0, 0, swipeableCell.bounds.size.width, swipeableCell.bounds.size.height)];
} completion:^(BOOL finished) {
[_storedCells removeLastObject];
}];
Run Code Online (Sandbox Code Playgroud)
如果我将其翻译成Swift,它应该看起来像这样:
UIView.animateWithDuration(0.5, animations: {
self.storedCells[1].topLayerView.frame = CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height)
}, completion: { (finished: Bool) in
//self.storedCells.removeAtIndex(1)
})
Run Code Online (Sandbox Code Playgroud)
它在评论线上抱怨.我收到的错误是:Could not find an overload for 'animateWithDuration' that accepts the supplied arguments
我知道完成闭包需要一个布尔值并返回一个void,但是我应该能够写出一些与bool无关的东西....对吧?
任何帮助表示赞赏.
编辑:这是我如何在函数中声明我正在使用的数组:
var storedCells = SwipeableCell[]()
Run Code Online (Sandbox Code Playgroud)
一个采用SwipeableCell对象的数组.
我曾经习惯于UIView animateWithDuration增加shapeLayer.frame.size.height下面的代码,但无论持续时间如何,都会非常快.我发现的一些帖子推荐使用了我已经完成的一些延迟时间,但它仍然很快动画,忽略了我设置的5秒持续时间.
private let minimalHeight: CGFloat = 50.0
private let shapeLayer = CAShapeLayer()
override func loadView() {
super.loadView()
shapeLayer.frame = CGRect(x: 0.0, y: 0.0, width: view.bounds.width, height: minimalHeight)
shapeLayer.backgroundColor = UIColor(red: 57/255.0, green: 67/255.0, blue: 89/255.0, alpha: 1.0).CGColor
view.layer.addSublayer(shapeLayer)
}
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
override func viewDidAppear(animated: Bool) {
delay(3) {
UIView.animateWithDuration(5.0) {
self.shapeLayer.frame.size.height += 400.0
}
}
Run Code Online (Sandbox Code Playgroud)
如何在5秒内完成动画制作?
我正在实现一个通过用户输入动画的健康栏.
这些动画使其上下移动一定量(比如50个单位)并且是按下按钮的结果.有两个按钮.增加和减少.
我想在运行状况栏上执行锁定,以便一次只能有一个线程更改它.问题是我遇到了僵局.
我猜是因为一个单独的线程运行另一个线程持有的锁.但是当动画完成时,该锁将会让位.如何实现在[UIView AnimateWithDuration]完成时结束的锁定?
我想知道是否NSConditionLock可行,但我想尽可能使用NSLocks以避免不必要的复杂性.您有什么推荐的吗?
(最终我希望动画"排队",同时让用户输入继续,但是现在我只想让锁定工作,即使它首先阻止输入.)
(嗯,想到它只有一个[UIView AnimateWithDuration]一次运行同一个UIView.第二个调用将中断第一个,导致完成处理程序立即运行第一个.也许第二个锁运行之前首先有机会解锁.在这种情况下处理锁定的最佳方法是什么?也许我应该重新审视Grand Central Dispatch但是我想看看是否有更简单的方法.)
在ViewController.h中我声明:
NSLock *_lock;
Run Code Online (Sandbox Code Playgroud)
在ViewController.m中我有:
在loadView中:
_lock = [[NSLock alloc] init];
Run Code Online (Sandbox Code Playgroud)
ViewController.m的其余部分(相关部分):
-(void)tryTheLockWithStr:(NSString *)str
{
LLog(@"\n");
LLog(@" tryTheLock %@..", str);
if ([_lock tryLock] == NO)
{
NSLog(@"LOCKED.");
}
else
{
NSLog(@"free.");
[_lock unlock];
}
}
// TOUCH DECREASE BUTTON
-(void)touchThreadButton1
{
LLog(@" touchThreadButton1..");
[self tryTheLockWithStr:@"beforeLock"];
[_lock lock];
[self tryTheLockWithStr:@"afterLock"];
int changeAmtInt = ((-1) * FILLBAR_CHANGE_AMT);
[self updateFillBar1Value:changeAmtInt];
[UIView animateWithDuration:1.0
delay:0.0
options:(UIViewAnimationOptionTransitionNone|UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionAllowUserInteraction)
animations:
^{
LLog(@" BEGIN animationBlock - val: …Run Code Online (Sandbox Code Playgroud) 我有一个动画,当手势识别器(双击)触发时,它会被踢掉:
[UIView animateWithDuration:0.3 animations:^{
_scrollView.contentOffset = CGPointMake(x, y);
_scrollViewContentView.frame = someFrame;
_scrollViewContentView.layer.transform =
CATransform3DMakeScale(1.f/_zoomScale, 1.f/_zoomScale, 1.f);
}];
Run Code Online (Sandbox Code Playgroud)
除了一种情况之外它工作得很好:如果scrollViewWillBeginDecelerating在动画执行之前没有调用委托方法(只是拖动几乎我的scrollview).
我只是有scrollViewDidEndDragging方法叫.我可以等20秒,然后播放我的动画.它会正常播放,除了我的contentOffset.
委托方法本身什么都不做,只是添加它们才能看出问题所在.
我不知道为什么.
编辑:这是我的问题视频.第1阶段:减速滚动,第2阶段没有.看看最后的位置.阶段1是正确的但不是阶段
objective-c uiscrollview ios contentoffset animatewithduration
我有一个简单的动画,我在滚动视图委托方法中执行scrollViewDidEndDragging.
它看起来像这样:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
NSLog(@"finger was lifted");
[UIView animateWithDuration:1.0
animations:^{
self.homeLabel.frame = self.view.frame;
}];
}
Run Code Online (Sandbox Code Playgroud)
在抬起手指后使用这个动画我的homeLabel是从顶部来的,我想在标签上添加一个反弹动画,所以当它来自顶部时,而不是顺利着陆它会有一个很好的反弹...我怎么能去做?thanksss
animation core-animation objective-c ios animatewithduration
我想动画调整UICollectionViewCell的大小.我已经编写了下面的代码,但不能return在动画块中包含该行.有任何想法吗?
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
var newSize = CGSize(width: (self.view.frame.width), height: 0)
UIView.animateWithDuration(2.0, animations: { () -> Void in
return newSize
})
}
Run Code Online (Sandbox Code Playgroud) ios uicollectionviewcell uicollectionviewlayout animatewithduration swift
我有一个按钮,调用animateWithDuration代码,淡出图像,淡化文本和新的bg颜色,然后重置为正常.动画需要几秒钟才能完成并且效果很好.
然而!有一个问题:
有时在动画结束前会再次按下此按钮.当发生这种情况时,我希望当前的动画停止并重新开始.
研究解决方案不起作用
根据我的解读,解决方案应该很简单,只需导入QuartzCore并添加:
button.layer.removeAllAnimations()
Run Code Online (Sandbox Code Playgroud)
这确实会移除动画但新/秒动画完全搞砸了.应该隐藏的图像不是,文本永远不会显示,颜色过渡都是错误的.发生了什么!?!
//Animate Finished feedback in footer bar
func animateFinished(textToDisplay: String, footerBtn: UIButton, footerImg: UIImageView) {
//Should cancel any current animation
footerBtn.layer.removeAllAnimations()
footerBtn.alpha = 0
footerBtn.setTitle(textToDisplay, forState: UIControlState.Normal)
footerBtn.titleLabel!.font = UIFont(name: "HelveticaNeue-Regular", size: 18)
footerBtn.setTitleColor(UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0), forState: UIControlState.Normal)
footerBtn.backgroundColor = UIColor(red: 217/255.0, green: 217/255.0, blue: 217/255.0, alpha: 1.0)
UIView.animateWithDuration(0.5, delay: 0.0, options: nil, animations: {
footerImg.alpha = 0.01 //Img fades out
footerBtn.backgroundColor = UIColor(red: 46/255.0, green: 163/255.0, blue: 00/255.0, …Run Code Online (Sandbox Code Playgroud) 我有两种状态UIView:

@IBaction我在它们之间使用for进行动画button:
@IBAction func tapped(sender: UIButton) {
flag = !flag
UIView.animateWithDuration(1.0) {
if self.flag {
NSLayoutConstraint.activateConstraints([self.myConstraint])
} else {
NSLayoutConstraint.deactivateConstraints([self.myConstraint])
}
self.view.layoutIfNeeded() //additional line
}
}
Run Code Online (Sandbox Code Playgroud)
仅当我添加附加行时动画才起作用:
但是当我删除该行时,我的UIView就会更新但没有任何动画,它会立即发生。
为什么这条线会产生如此大的差异?运作如何?