Titanium - Reset zoom scale in webview - titanium

Is it possible to programmatically reset the zoom/scale that the user has done in a webview? My issue is when the webview is pinch zoomed in landscape and you rotate the phone, the webview is still zoomed in and in my case, portrait mode is now extremely zoomed in.
I've tried webview.repaint() but that seems to do absolutely nothing. I know I can call webiew.reload() but that just uses more bandwidth for my server as well as the users data plan so I want to avoid that.
I'm using Titanium Studio, build: 3.1.3.xxx, 3.1.3 GA Ti SDK and compiling for iOS 7 SDK.

Based on this thread and the fact that there was no way to easily achieve this, I have created a module. It extends the Ti.UI.WebView with two methods, setZoomLevel() and scrollToTop(). It is very basic at the moment, but I'm planning on extending its functionality gradually.
https://github.com/mwfire/titanium-module-extended-webview
Have a look, it's an alternative to modifying the core code.

Did you give a try at setting the scalesPageToFit property of your webview upon orientation change?
http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.WebView-property-scalesPageToFit

I found the answer which was a bit more than I wanted to do. I had to actually modify the Titanium SDK obj-c files.
I modified 3 files:
TiUIWebView.h
-(void)resetZoomScale; //-- added this line to define the function in the header file
TiUIWebView.m
//-- Added this function that will actually handle the resize
- (void)resetZoomScale
{
[webview.scrollView setZoomScale:1.0]; //-- reset the scroll view back to 1
}
TiUIWebViewProxy.m
//-- Call the resetZoomScale function in TiUIWebView.m file
//-- I believe this also exposes the function to javascript
-(void)resetZoomScale:()args
{
TiThreadPerformOnMainThread(^{[(TiUIWebView*)[self view] resetZoomScale];}, NO);
}
I can now call myWebView.resetZoomScale(); and whatever pinch/zooming has been done on the web view will be reset back none or 1

Related

Xcode objective C: How Clean code from UIWebView (ITMS-90809)

I use Windev mobile to developpe apps for both Android and IOS. For IOS apps, Windev mobile gave me an objective-c project that i should build in xcode then send to app store ..
I'm know only basics of basics step on xcode and i need to clean my code from "UIWebView", I have seen more than discussion about that but none of them repond to my case ..
For exemple thay talk about using: grep -r UIWebView project path .
But i realy dont know how to use that ...
Please your help will be very very appreciated !
Thanks!
Really just some guidance - how to do it actually depends on your situation.
Don't use grep - just use your IDE's search to locate all the UIWebView and then replace them with WKWebView. It can be as simple as that depending on what you use your webview's for. If for complex processing then you'll need to figure out how to do what you did in UIWebView in the WKWebView.
Another suggestion - why not wrap all your UIWebViews in some custom class and move all the functionality in there. Then it is easy to replace the UIWebView there and also rework the functionality there with the class staying the same. Apart from the functionality you'll have code that looks something like this in there.
+ ( UIWebView / WKWebView * ) addWebViewToView:( UIView * ) view
{
// Code to create webview - initially UIWebView and later WKWevView
..
// Code to embed the webview into the view
.. set the constraints to fill the view
return webview;
}
Then you can use normal UIView's in your project and use this to prime them with a webview.
To this you can later add navigation delegates to beef up the functionality or, if you just use the webview to display some HTML, you can pass in the string or URL to display.

iOS8 how to understand interface orientation from UIViewControllerTransitionCoordinator?

I'm debugging a project that was working fine in iOS7.1, but does not lay out it's content properly in iOS 8.0. I've narrowed the issue down to this method:
[self orientRootViewControllerForOrientation:rootViewController.interfaceOrientation];
iOS8 no longer returns correct UIInterfaceOrientation from rootViewController.interfaceOrientation, instead it returns "upside down".
Reading the documentation, I'm confronted with a cryptic message:
Use viewWillTransitionToSize:withTransitionCoordinator: to make
interface-based adjustments.
Reading documentation on UIViewControllerTransitionCoordinator, I don't see it having any properties. How can I modify my method that expects an interface orientation to get it's orientation from UIViewControllerTransitionCoordinator?
Basically you are supposed now to layout your content based on the available size, no more on the rotation. Which results in big pains to support older rotation-based code.
The view controller transition coordinator provides a UIViewControllerTransitionCoordinatorContext that has a rotation factor. This could give you the hint you need ?
This blog post mentions this too.
You also have the usual device ([UIDevice currentDevice].orientation) or status bar orientation.
In case you are working on iOS 6 rotation methods, this post has relevant informations too.

iOS 5 - Camera Overlay Clone

Is there an open source nib out that that's a clone of the overlay view that Apple uses for its Camera.app? I'm currently using UIImagePickerController with picker.showCameraControls = YES, but I need to tweak the functionality ever so slightly.
I've been thinking of subclassing the UIImagePickerController, but would that give me more control over takePicture? Specifically, I want to be able to call that method without forcing the user to leave the interface.
This is what the AVCaptureSession class is for. The documentation shows how to set up a captureSession, from there it's all cake!

How do I use a RootViewController when making an app without a ViewController?

I am trying to make a simple app from a tutorial that does not have a viewController at all. All the code is in the AppDelegate. I am on xcode 4.2 and I am getting this error:
Applications are expected to have a root view controller at the end of application launch
I'm not sure how to deal with this. There are some blogs out there with fixes but none of them are working for me and I really would like to understand what is going on here. And, how to fix it.
I do have a view that contains some buttons and labels. But I have no "ViewController". The files contained in my project are: AppDelegate.h, AppDelegate.m, and Window.xib only. There is no ViewController.h, ViewController.m
** edit **
I ended up making the app from a 'view based application' instead and just moving all the logic from the app delegate to the view controller. So, I didn't really solve the problem per se. The app works now though. Thanks for the help
It's not possible to have an iOS app that doesn't have a view controller. You can always create a trivial view controller, i.e.,
[[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds].rootViewController =
[[[UIViewController alloc] init] autorelease];
It sounds like you're looking at an old tutorial. UIWindow got a rooViewController property in iOS4. I believe it became required in iOS5 to help keep controller hierarchies and view hierarchies in sync with the addition of custom container controllers (and to fix a corner case where replacing the "root controller" of a UIWindow could stop orientation changes from propagating). There was a WWDC presentation in 2011 that explained this in some detail. I think it was Session 102, Implementing UIViewController Containment.
At then end of the day, there's no good reason not to have a root view controller. Apple wants to be able to assume it's there in their APIs going forward. If the tutorial you're looking at doesn't account for that, it's broken.
While I agree that there may be workarounds, another question to address is: why do you want an app without a view? Even if it's designed to run in the background and present no visual interface, at least make a simple view showing the application name and version, a largeish icon and perhaps a status. This kind of idle screen uses very little system resources, especially when the app is backgrounded, but improves the overall experience of the app.
If you set your deployment target to 4.3 and run on the iPhone 4.3 simulator, you won't get the warning.
To install the iOS 4.3 simulator, go to Xcode > Preferences > Downloads.

iOS 5 bug: UIWebView and goBack and goForward

I found a bug in iOS 5.
When you are using a UIWebView and access some sites, you create your history links, look like any other browser.
If you like to use a navegation bar, can use the functions goBack and goForward
In iOS 4.3 and below, when you call this function the program call the delegate function
webView:shouldStartLoadWithRequest:navigationType:
But in iOS 5.0 this can happens or not. If the site is in cache, it not call this function. I saw this happens in only 1 level (1 click in goBack or 1 to goFoward), in the second click it pass in the function.
Why they change it???? Even it is in cache, the program have to ask for me.. Now how solve this: I am trying make a stack with the browser history and I check the url. But i am having problem ;(
There are no other way?
I can't see the browser history? I have to create my ow list?
I can't clean the cache to force it pass in the function?
Any sugest?
It's not a bug, if there is enough available RAM on the device then it will keep some of the pages in memory, therefore they are not being "loaded" again when you go back.
You should create your own goBack: and goForward: actions on your own controller, and link the goBack/goForward buttons to them:
- (IBAction)goBack:(id)sender
{
[self doStuff];
[self.webView goBack:sender];
}