我正在使用此函数将MKMapView实例渲染为图像:
@implementation UIView (Ext)
- (UIImage*) renderToImage
{
UIGraphicsBeginImageContext(self.frame.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Run Code Online (Sandbox Code Playgroud)
这很好用.但是使用iphone4时,渲染图像的分辨率与设备上的分辨率不同.在设备上我具有640x920地图视图质量,渲染图像具有320x460的分辨率.然后我将提供给UIGraphicsBeginImageContext()函数的大小加倍,但填充了唯一的左上角图像部分.
问题:有没有办法将地图渲染为具有全分辨率640x920的图像?
第一个屏幕截图是在全屏播放视频之前拍摄的.
第二个是在视频全屏打开并关闭后拍摄的.
知道为什么导航工具栏有扩展吗?
注意:汉堡包按钮不是导航项的一部分.它在父级的覆盖中伪造,将其子控制器保存在标准容器中.
源内没有什么特别之处:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
bbiListic = UIBarButtonItem(image: UIImage(identifier: .IcoHeaderListic), style: .Plain, target: self, action: #selector(UIViewController.showListic))
bbiFavorite = UIBarButtonItem(image: UIImage(identifier: .IcoHeaderStarEmpty), style: .Plain, target: self, action: #selector(LiveDogadjajViewController.toggleFavorite(_:)))
...
let items = [bbiListic!,bbiFavorite!]
navigationItem.rightBarButtonItems = items
}
func someRefresh() {
var items = [UIBarButtonItem]()
items.append(bbiListic!)
...
navigationItem.rightBarButtonItems = items
}
Run Code Online (Sandbox Code Playgroud)
更新:
这似乎仅在最新版本的iOS 9.3上存在问题
我在iOS应用程序中使用JavaScriptCore库,我正在尝试实现setTimeout函数.
setTimeout(func, period)
Run Code Online (Sandbox Code Playgroud)
启动应用程序后,将创建具有全局上下文的JSC引擎,并向该上下文添加两个函数:
_JSContext = JSGlobalContextCreate(NULL);
[self mapName:"iosSetTimeout" toFunction:_setTimeout];
[self mapName:"iosLog" toFunction:_log];
Run Code Online (Sandbox Code Playgroud)
这是本机实现,它将具有所需名称的全局JS函数映射到静态目标C函数:
- (void) mapName:(const char*)name toFunction:(JSObjectCallAsFunctionCallback)func
{
JSStringRef nameRef = JSStringCreateWithUTF8CString(name);
JSObjectRef funcRef = JSObjectMakeFunctionWithCallback(_JSContext, nameRef, func);
JSObjectSetProperty(_JSContext, JSContextGetGlobalObject(_JSContext), nameRef, funcRef, kJSPropertyAttributeNone, NULL);
JSStringRelease(nameRef);
}
Run Code Online (Sandbox Code Playgroud)
这里是目标C setTimeout函数的实现:
JSValueRef _setTimeout(JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception)
{
if(argumentCount == 2)
{
JSEngine *jsEngine = [JSEngine shared];
jsEngine.timeoutCtx = ctx;
jsEngine.timeoutFunc = (JSObjectRef)arguments[0];
[jsEngine performSelector:@selector(onTimeout) withObject:nil afterDelay:5];
}
return JSValueMakeNull(ctx);
}
Run Code Online (Sandbox Code Playgroud)
一段延迟后应该在jsEngine上调用的函数:
- …Run Code Online (Sandbox Code Playgroud)