有一个简单的一次性任务,需要一个进度条.OpenSSL有一个有用的回调,可用于此:
rsa=RSA_generate_key(bits,RSA_F4,progressCallback,NULL);
Run Code Online (Sandbox Code Playgroud)
同
static void callback(int p, int n, void *arg) {
.. stuff
Run Code Online (Sandbox Code Playgroud)
但是我想从ObjectiveC中调用它而不需要太多麻烦:
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = @"Generating CSR";
[self genReq:^(int p,int n,void *arg) {
hud.progress = --heuristic to guess where we are --
} completionCallback:^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
}];
Run Code Online (Sandbox Code Playgroud)
使用Genrec:作为objC方法:
-(void)genReq:(void (^)(int,int,void *arg))progressCallback
completionCallback:(void (^)())completionCallback
{
.....
rsa=RSA_generate_key(bits,RSA_F4,progressCallback,NULL);
assert(EVP_PKEY_assign_RSA(pkey,rsa));
rsa=NULL;
....
completionCallback();
}
Run Code Online (Sandbox Code Playgroud)
现在completionCallback(); 工作得非常出色,如预期的那样.但我得到一个编译器警告/错误,我无法平息进度回调:
Passing 'void (^__strong)(int, int, void *)' to parameter of incompatible type 'void (*)(int, int, void …Run Code Online (Sandbox Code Playgroud) 移动到10.12/Sierra和Xcode 8.1之后,我正在敲打一个奇怪的错误:
+[NSTimer scheduledTimerWithTimeInterval:repeats:block:]:
unrecognized selector sent to class 0x7fff78f1fa88
Run Code Online (Sandbox Code Playgroud)
重现这一点的最小代码(创建新项目的默认设置)是:
// AppDelegate.m
//
#import "AppDelegate.h"
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@property (strong, nonatomic) NSTimer * timer;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.timer = [NSTimer scheduledTimerWithTimeInterval:10
repeats:YES
block:^(NSTimer * _Nonnull timer)
{
NSLog(@"Ping from %@", timer);
}];
}
Run Code Online (Sandbox Code Playgroud)
链接包括(核心)基础类和'all_load'.必须是完全无足轻重的东西 - 但不是它的本质.
任何和所有帮助表示赞赏.
谢谢,
DW.
在绘制到屏幕外缓冲区时,我正在努力让Image Insets工作.
在UIImage上直接使用resizableImageWithCapInsets:setImage:into按钮对我来说很好用:
UIImage * base = [UIImage imageNamed:@"button.png"];
UIImage * img = [base resizableImageWithCapInsets:UIEdgeInsetsMake(20,20,20,20)];
[self setImage:img forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
如下所示(左边是原始缩放,右边是使用insets缩放):

所以正确的一个很好 - 顶部/底部/左/右的线是等距的.到现在为止还挺好.
现在,如果我尝试使用绘制的图像进行相同的操作,然后将其捕获到屏幕外缓冲区,其中:
UIImage * base = [UIImage imageNamed:@"button.png"];
base = [base resizableImageWithCapInsets:UIEdgeInsetsMake(20,20,20,20)];
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0);
ctx = UIGraphicsGetCurrentContext();
CGContextDrawImage(ctx, CGRectMake(0,0,self.bounds.size.width,
self.bounds.size.height), [base CGImage]);
img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self setImage:img forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
我得到了下面(再次左边是原始缩放,右边是插图):

.
所以这里似乎忽略了插图.
有人对这里出了什么问题有任何建议吗?在全功能例如http://people.apache.org/~dirkx/insetSample.zip,只是在关键代码http://pastebin.com/rm8h6YFV.
任何和所有建议表示赞赏.
DW