I need to display webview in cocos2D game. I used this code. But it is not displaying close button, how can I enable close button? Here is screen that I want:
Code Used:
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
UIWebView* myWebView = [[[UIWebView alloc] initWithFrame:webFrame] autorelease];
myWebView.backgroundColor = [UIColor whiteColor];
myWebView.scalesPageToFit = YES;
myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
myWebView.delegate = self;
[self.navController.view addSubview:myWebView];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://biggooseegg.com/moregamesscreen"]]];
Some other doubts: How can I get rounded border for this web view?
Here is my sample that not completed.
The close button isn't part of UIWebView, you'll have to add it yourself.
Rounded corners can be achieved by displaying said rounded corners background image behind the UIWebView. You can use a CCSprite for that. Then make the web view fit inside the background image.
Related
This is a problem I am facing in portrait mode. The UIWebView is in fullscreen and the title bar is not starting from the screen size.
I want to hide the little portion which shows battery, and time status. This portion shows after scrolling the web view.
I have used this code:
NSLog(#"loadWebView1");
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
contentView.autoresizesSubviews = YES;
self.view = contentView;
//set the web frame size
CGRect webFrame = [[UIScreen mainScreen] bounds];
webFrame.origin.y = 0;
//add the web view
theWebView = [[UIWebView alloc] initWithFrame:webFrame];
theWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
theWebView.scalesPageToFit = YES;
theWebView.delegate = self;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[theWebView loadRequest:req];
[self.view addSubview: theWebView];
if you want to hide it for a single view the you can do it like this
-(BOOL)prefersStatusBarHidden {
return true;
}
if you want to hide it for all the views then you can do from TARGETS
check the Hide status bar checkmark
Set "View controller-based status bar appearance" to "true" in Info.plist.
Then, place the following code in the desired view controller:
- (BOOL)prefersStatusBarHidden {
return true
}
I want to add a subView to this WKWebView with this content (https://www.windytv.com/?-34.816,138.608,5). so that the subView can be panning along with the webview (imagine there's landmark view being panning along), but I could do it.
I tried many ways as follows:
I add a landmarkView to different subViews of the webView, failed.
1.1 For example:
[self.webView addSubView:landmarkView];
1.2 Or:
[self.webView.scroolView addSubView:landmarkView];
1.3 Or:
[self.webView.scroolView.subViews.firstObject addSubView:landmarkView]; // In viewDidAppear
The interesting thing here is the view hierachy of WKWebsite will change in viewDidAppear. It gets more subView like "WKContentView".
Followed by 1., I try to add a gestureView to pass the gesture to move the landmarkView, failed. The action of the gesture did not procceed.
1.1. For example, I add on the super view of webView.
[self.view addSubView: baseView];
[self.baseView addSubView: webView];
self.panGestureRecognizer.cancelsTouchesInView = NO;
[webView addGestureRecognizer: self.panGestureRecognizer];
Or, I add on the subView of webView.
[self.view addSubView: webView];
[self.webView addSubView: gestureView];
gestureView.backgroundColor = [UIColor clearColor];
self.panGestureRecognizer.cancelsTouchesInView = NO;
[gestureView addGestureRecognizer: self.panGestureRecognizer];
Anyone familiar with WKWebView?
Except for UIGesture, Is there other ways to distribute a touch to many views?
If I could override the touchesBegan method in one of the subViews, it should be much easier. And I think hitTest still work only on a view.
The general
- (void)viewDidLoad
{
UIView *landmarkView = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 200, 200)];
landmarkView.backgroundColor = [UIColor redColor];
NSString *path = #"https://www.windytv.com/?-37.331,145.102,7";
NSURL *url = [NSURL URLWithString:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
[self.view addSubView: self.webView];
[self.webView.scrool addSubView:landmarkView]; // This is one of the failed attempts.
}
It can be solved by adding a panGesture with this delegate method.
The trick is introduced here:
UIPanGestureRecognizer on MKMapView?
I created a GIF and it is basically snow particles falling and has a transparent background. Therefore I can have just snow flowing over my other PNGs and images on the app. The problem is that the app loads and the GIF appears all white. Not sure why because I gave it transparency when making it. If I lower the alpha in Xcode I still don't see my old PNGs (usual background image).
This is in my ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"snow" ofType:#"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:#"image/gif" textEncodingName:nil baseURL:nil];
webViewBG.userInteractionEnabled = NO;
[self.view addSubview:webViewBG];
UIView *filter = [[UIView alloc] initWithFrame:self.view.frame];
//filter.backgroundColor = [UIColor redColor];
filter.alpha = 0.5;
[self.view addSubview:filter];
You can set your view background Clear color And for animated image you can use UIImageView.
hope this will be work proper.
See Link:: - Click here to get code
Link2::- Click here for code
I use UIWebView to load a html page which contains only one SVG image file with below code:
self.webView = [UIWebView new];
self.webView.opaque = YES;
self.webView.frame = self.view.frame;
[_webView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
self.webView.dataDetectorTypes = UIDataDetectorTypeAll;
self.webView.userInteractionEnabled = YES;
_webView.scalesPageToFit = YES;
self.webView.delegate=self;
[self.view addSubview:self.webView];
and I take the a screen capture as below, I want to make the image file can be auto zoom in to fit the whole window when View is shown, currently I had to double tab the image to make it happen.
and belwo is what I expected:
Found the answer
NSString *jsCommand = [NSString stringWithFormat:#"document.body.style.zoom = 1.5;"];
[_webview stringByEvaluatingJavaScriptFromString:jsCommand];
I want my ViewController and every object appear inactive by having it all grayed out (kind of like how the UIAlertView popup grays out everything in the background). I do not want to have to manually gray out every object there is.Is there an easy way to make this work?
UIView *grayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
grayView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
[self.view addSubview:grayView];
You can mess with the white and alpha values to get exactly what you want, but that should put a gray tint over everything in your view controller's view.
As Patrick Goley pointed with his good answer - just put a gray UIView with alpha between 0.5 - 0.75 above your original view. But this method will disable all the user interactions with its subviews (buttons,etc). If you want to preserve user interactions with the elements but nevertheless mark the view as "inactive", you should subclass the view which you will put above your original view (which you want to mark as inactive) and in this subclass override this method:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
// Original "inactive" UIView will now respond to touch events if return NO:
return NO;
}
This code will cover also any parent controller: UINavigationController | UITabBarController.
Don't forget #import "AppDelegate.h".
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
UIView *grayView = [[[UIView alloc] initWithFrame:appDelegate.window.bounds] autorelease];
grayView.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.8];
[appDelegate.window addSubview:grayView];
I prefer to add a UIView that has a black background, and then lower the alpha.
UIView *grayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
grayView.backgroundColor = [UIColor blackColor];
[grayView setAlpha:0.65];
And then do not forget to add the subview to your main view
[self.view addSubView:grayView];
Yes:
Set the alpha of the view
[self.view setAlpha:0.5];