【发布时间】:2015-01-13 12:54:54
【问题描述】:
我已经在 Google/Stackoverflow 中搜索了关于此的“所有内容”,但我仍然卡住了。我刚刚开始开发 OSX 应用程序,所以我是 Objective-C 和 Xcode 5 (5.0.2) 的(几乎)完整新手。
我只需要一个简单的 webview 来从给定的 URL 加载 webgame。这个 webview 的行为必须像一个非常简单的 Safari 浏览器。我的应用程序已经运行得比较好。它可以正常加载游戏,经过一番挣扎后,我成功地让它显示了 javascript 警报并确认。
我现在的任务是使捏缩放工作。那是我的 appDelegate.M:
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize myWebView;
// Enables confirms:
- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
NSInteger result = NSRunInformationalAlertPanel(NSLocalizedString(@"Confirmação", @""), // title
message, // message
NSLocalizedString(@"OK", @""), // default button
NSLocalizedString(@"Cancelar", @""), // alt button
nil);
return NSAlertDefaultReturn == result;
}
// Enables alerts:
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:message];
[alert runModal];
//[alert release];
}
// This was supposed to enable pinch zoom:
- (void)magnifyWithEvent:(NSEvent *)event {
//[resultsField setStringValue:
//[NSString stringWithFormat:@"Magnification value is %f", [event magnification]]];
NSSize newSize;
newSize.height = [[NSScreen mainScreen] frame].size.height * ([event magnification] + 1.0);
newSize.width = [[NSScreen mainScreen] frame].size.width * ([event magnification] + 1.0);
//[self setFrameSize:newSize];
[myWebView setFrameSize:newSize];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
[self.window setContentView:self.myWebView];
[self.window toggleFullScreen:@""];
[myWebView setMainFrameURL:@"http://www.mywebgameurl.com"];
}
@end
显然,- (void)magnifyWithEvent:(NSEvent *)event 中的代码不起作用。应用程序构建并运行,但当我捏捏时没有任何反应。
换句话说,我需要启用 web 视图来使用触控板捏合功能进行放大和缩小。我已经在 Android 中开发了一个非常相似的 webview,我所要做的就是添加webSettings.setBuiltInZoomControls(true);
webSettings.setSupportZoom(true);。我只是在寻找类似的东西。欢迎任何帮助,谢谢!
【问题讨论】:
标签: objective-c macos cocoa webview pinchzoom