我正在设置以下UIView animateWithDuration:
方法,目的是animationOn
在程序中的其他位置设置我的BOOL以取消无限循环重复.我的印象completion
是每次动画循环结束时都会调用该块,但事实并非如此.
是否completion
在重复动画中调用了块?如果没有,是否有另一种方法可以在此方法之外停止此动画?
- (void) animateFirst: (UIButton *) button
{
button.transform = CGAffineTransformMakeScale(1.1, 1.1);
[UIView animateWithDuration: 0.4
delay: 0.0
options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations: ^{
button.transform = CGAffineTransformIdentity;
} completion: ^(BOOL finished){
if (!animationOn) {
[UIView setAnimationRepeatCount: 0];
}
}];
}
Run Code Online (Sandbox Code Playgroud) core-animation objective-c uiviewanimation ios completion-block
在我的应用程序中,我使用TTOpenInAppActivity在UIActivityController中插入"Open in"动作.里面它的工作原理如下:
一些视图控制器呈现UIActivityController,内置TTOpenInActivity.
-(void)openWithAction
{
NSURL *fileURL = SOME_URL;
CGRect rect = SOME_RECT;
TTOpenInAppActivity *openInAppActivity = [[TTOpenInAppActivity alloc] initWithView:self.view andRect:rect];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[fileURL] applicationActivities:@[openInAppActivity]];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
// Store reference to superview (UIActionSheet) to allow dismissal
openInAppActivity.superViewController = activityViewController;
// Show UIActivityViewController
[self presentViewController:activityViewController animated:YES completion:NULL];
} else {
// code for iPad, irrelevant
}
}
Run Code Online (Sandbox Code Playgroud)
当用户点击"打开"按钮时,将触发以下方法:
- (void)performActivity
{
if(!self.superViewController){
[self activityDidFinish:YES];
return;
}
// Dismiss activity view
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
// iPhone dismiss UIActivityViewController
[self.superViewController …
Run Code Online (Sandbox Code Playgroud) ios uiactivity uiactivityviewcontroller ios8 completion-block
我有以下代码:
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction
animations:^{
imageView.bounds = endBounds;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 delay:0.5 options:UIViewAnimationOptionAllowUserInteraction
animations:^{
imageView.bounds = startBounds;
}
completion:^(BOOL finished) {
[imageView removeFromSuperview];
}];
}];
Run Code Online (Sandbox Code Playgroud)
另外我有:
[imageView setUserInteractionEnabled:YES];
Run Code Online (Sandbox Code Playgroud)
以及一个轻击手势识别器设置,用于处理用户点击imageView.当第一个动画发生时,手势识别器会像我期望的那样触发.但是如果我尝试在完成块的链式动画中点击imageView,即使我已经设置了适当的选项也没有任何反应.
有人有什么想法?我用谷歌搜索,找不到答案.
我在Debug和Release中有一个完成块的奇怪行为.例如:
sourceViewController.presentViewController(ccVC, animated: true, completion: { () -> Void in
NSUserDefaults.standardUserDefaults().setBool(true, forKey: kChromeCastInstructionsShown)
NSUserDefaults.standardUserDefaults().synchronize()
println("save bolean")
})
Run Code Online (Sandbox Code Playgroud)
在调试中:println("save bolean")print string在relase:println("save bolean")中不打印任何内容
对这种行为有什么想法吗?有人试验一个明确的解决方案?
亲切的安德里亚
我有下面的代码,但在使用Xcode 7和Swift 2.0构建时出现错误
错误是Cannot call value non-function type (([CKRecord]?, [CKRecordID]?, NSError?) -> Void)?
谢谢
let saveRecordsOperation = CKModifyRecordsOperation()
var ckRecordsArray = [CKRecord]()
// set values to ckRecordsArray
saveRecordsOperation.recordsToSave = ckRecordsArray
saveRecordsOperation.savePolicy = .IfServerRecordUnchanged
saveRecordsOperation.modifyRecordsCompletionBlock { savedRecords, deletedRecordIDs, error in
// deal with conflicts
// set completionHandler of wrapper operation if it's the case
if saveRecordsOperation.finished == true {
}
}
database.addOperation(saveRecordsOperation)
Run Code Online (Sandbox Code Playgroud) 在 Objective-C 中,我有一个完成块类定义为:
文件.h
typedef void (^MYCompletionBlock)(BOOL success, NSDictionary *result, NSError *error);
Run Code Online (Sandbox Code Playgroud)
然后,在 Swift 文件中,我尝试使用完成块,如下所示:
斯威夫特.斯威夫特
class MyClass: NSObject{
...
func MyFunction() -> Void {
...
objcMethod(param1, withCompletion: {(MYCompletionBlock) -> Void in
if (success){ // Error:"Use of unresolved identifier 'success'"
}
}
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
但是,我不断收到错误:“使用未解析的标识符‘成功’”。
我也尝试过以下方法:
objcMethod(param1, withCompletion: {(success:Bool, result: NSDictionary, error:NSError) -> Void in
if (success){ // Error:"Cannot convert value of type '(Bool, NSDictionary, NSError) -> Void' to expected argument type "MYCompletionBlock!"
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我理解如何在 Swift 中正确指定 …
我们有一个函数,当它完成另一个函数时应该在它的完成块中调用,但是在完成块内的任何东西都不会被调用.这是功能:
func appendAllData (completion: () -> Void) {
guard let movieDetails = self.movieDetailsData else {
// handle nil case
return;
}
if let posterImage = self.movieDetailsData?.poster {
self.posterArray.append(posterImage)
}
if let overview = self.movieDetailsData?.overview {
self.overviewArray.append(overview)
}
if let releaseDate = self.movieDetailsData?.releaseData {
self.releaseInfoArray.append(releaseDate)
}
if let runtime = self.movieDetailsData?.runtime {
self.releaseInfoArray.append(String(describing: runtime))
}
if let genre = self.movieDetailsData?.genre {
if !genre.isEmpty {
self.releaseInfoArray.append(genre[0].name)
}
}
if let budget = self.movieDetailsData?.budget {
self.boxOfficeArray.append(budget)
}
if let revenue = self.movieDetailsData?.revenue { …
Run Code Online (Sandbox Code Playgroud) 我有两个执行异步的函数。
我尝试将它们“同步”:DispatchGroup 和 DispatchQueue
let queue = DispatchQueue(label: "com.company.app.queue", attributes: .concurrent)
let group = DispatchGroup()
queue.async(group: group) {
//func1
}
queue.async(group: group) {
//func2
}
group.notify(queue: queue) {
print("#3 finished")
}
Run Code Online (Sandbox Code Playgroud)
Func1 和 Func2 仅调用:
class func getDataFromUrl( url: URL, completion: @escaping ( Data?, URLResponse?, Error? ) -> ( ) )
{
URLSession.shared.dataTask( with: url )
{
data, response, error in
completion( data, response, error )
}.resume( )
}
Run Code Online (Sandbox Code Playgroud)
但问题是我不知道如何等待queue.async中的完成块..
有人有什么想法吗?
考虑这种情况.
-(void) mainMethod
{
[self subMethod1];
[self subMethod2];
}
Run Code Online (Sandbox Code Playgroud)
我的假设:
在调用时mainMethod
,它将调用第subMethod1
一个,然后调用subMethod2
.但是,没有规则说"完成subMethod1
唯一的,subMethod2
应该被称为".如果我使用一些延迟线或持续时间为的某些动画subMethod1
,控件将不会等待它完成.它将开始下一个过程.因此,subMethod2
可以在subMethod1
完成其工作之前调用它.我对吗?
题:
如何让subMethod2等待,直到subMethod1完成它的工作?
注意:我不想subMethod2
放入subMethod1
我有两种方法.我想在完成第一个任务后执行一个.我怎样才能做到这一点?
completion-block ×10
ios ×5
objective-c ×4
swift ×4
animation ×1
asynchronous ×1
closures ×1
gesture ×1
ios8 ×1
iphone ×1
methods ×1
swift2 ×1
uiactivity ×1
uiview ×1
xcode7 ×1