iPhone accelerometer in web applications - iphone

I want my website to change its layout according to the device positon. The site has 2 layout types: vertical(height > width) ang horizontal(width > height).
do you see any solution?
upd: I don't see any complexity in changing the site layout. I want to know is there any event to handle.
p.s. will iphone's browser change its orientation if i rotate the device 90 degree?
Dave, tnx for emendation.

There is a javascript event called onorientationchange sent when the orientation changes and also there is a property called orientation on the window object that tells what the current orientation is.
See the documentation for more info and sample.

Related

can not display on external display properly

I try to display an app in external display, actually, it is a giant Iphone monitor (height is 1.5 m and wild is .5m ) and running into an issue. It is that my app is displayed in landscape mode with height is 320px and wild is 460px. However, in the giant iphone, my app is half of screen. How can I make it fit 1.5m x 0.5 m. Are there any ways to trick an system so that I can display a full screen in gian Iphone monitor even though the height and width of actual iphone is 320 and 460 respectively.
Please help if you have any ideas. All answer are welcomed here. Thanks
Be sure you scale your output appropriately for the external display. Something like this should get you on your way:
// if an external screen is attached it will be in the array of screens
if ( [[UIScreen screens] count] > 1 )
{
UIScreen *screen2 = [[UIScreen screens] objectAtIndex:1];
CGRect screenBounds = screen2.bounds;
NSLog(#"Should scale external output to fit in %dx%d",
(int)screenBounds.size.width,
(int)screenBounds.size.height);
}
There's lots of good information in Apple's View Programming Guide for iOS and the reference for UIScreen.
I guess it's worth mentioning that you are very unlikely to get any UI interaction (touch events, etc) from an external display. Most displays aren't touch displays and I'm don't believe touch events are even supported on an external display. So, any configuration of the information displayed on the external display will need to be controlled from the iOS device.

Set UiWebView's minimumZoomScale and maximumZoomScale with custom value in iPhone/iPad Objective c

In my App for iPhone/iPad(in Objective C), there is a UiWebView which loads any site(by typing the URL). My UiWebView loads site successfully and it can be scrolled and Zoomed successfully.
But my app requirement is that the UiWebView will ZoomIn more than the specified mimimum Zoom level of UiWebView. My code used for setting my Zoom levals is:
webview.scrollView.minimumZoomScale=0.5;
webview.scrollView.maximumZoomScale=10.0;
webview.scrollView.zoomScale=webview.scrollView.minimumZoomScale;
By seeing the minimumZoomScale=0.5, it sets the Zoom level correctlt. But as soon as I started Zooming it out it Zoomed out the default minimum level and further it can not be Zoomed in at my described Zoom levels.
Please let me know if somebody has any idea or solution.
I used this answer: https://stackoverflow.com/a/10699622/422338
It seems that the UIWebView's max/min zoom levels are set from the web page (and hence the settings you provide to webView.scrollView.minimumZoomScale are ignored).
If you do not have control of the HTML site being visited, you could do a "hack" to inject a meta tag via javascript (using the stringByEvaluatingJavaScriptFromString: method on UIWebView). Would this suit your needs? If you get it working, let me know :).

wanted to implement brightness bar in ipad app

hey guys,
i am working on a ebook reader and in its course i wanted to allow the reader to reduce/increase the brightness accordingly. what i tried is ,placed a UISlider and gave the values as 0 and 1 for min and max respectively. I placed a imageView on the main view and aplied alpha component to the uiview which responds to the slider accordingly.
i succeeded but i know that it doesn't save the battery life of the ipad.
are there any predefined methods or framework which enables us to alter the brightness of the device.
thank you in advance
There is a private api call GSEventSetBacklightLevel(float). But if you are planning to submit this to the app store it will get rejected.
There is now of doing this via the public API, you could use, like you stated, a semi tranparent view with a black background over the window to make it look like you can control the brightness.,

iPhone/ iPad app development TV Out

HI,
I have just submitted my first application to iTunes for approval, however, there is one thing I really want to add to it ASAP.
I would like to code into an app that it can use the TV Out functions of both the iPhone and iPad? Ideally it would work in a similar way to how keynote works i.e. you see a bit more on the iPad itself than is projected on the TV, but even just mirroring the screen would be a step in the right direction.
I have searched all over for this and all I keep getting is about downloading jailbreaks for you iPhone to mirror the screen, which doesn't really help.
Thanks in advance,
If you just want to mirror, use my TVOutManager singleton. I've put up code to do this on github: https://github.com/robterrell/TVOutManager (Hmmm... I just noticed I haven't pushed the most recent code. I'll review and push new code asap.) I wrote up some detailed info about it at http://www.touchcentric.com/blog/archives/123 if you want to know the how's and why's.
Basically, just add the files to your project, and call:
[[TVOutManager sharedInstance] startTVOut];
If you want to do more than mirroring, read the docs on UIScreen. It's fairly trivial to create a UIWindow on the external screen (steal the bits from TVOutManager if you need to) and add subviews to it. This way you could have a Keynote-like controller on the device screen, while the main display is on the external display.
http://mattgemmell.com/2010/06/01/ipad-vga-output should get you started ...
Mirroring is not possible.
But to draw on an external display, just get the UIScreen object for the external display, then set the screen property of a UIWindow to it, (making sure to set the frame correctly etc) everything in that window should be drawn on the respective display.
Relative links:
developer.apple.com/library/ios/#documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html (look at screen property)
developer.apple.com/library/ios/#documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html (look at +screens)
(I don't have any reputation => can't post clickable links)
I think, you can't do this. You can only stream videos from iPod app.
But, if you have jailbreak on your device, try this (link) or take a look at this great YouTube video (link) showing exactly what you need.

Safari iPhone - How to detect zoom level and offset?

I looking for options on how to track user zooming and panning on a page when viewed in Safari on an iPhone. Safari exposes move and gesture events, so theoretically I can keep a running tally of pan and zoom operations, but that seems like overkill since the browser must track that internally.
Is this information exposed through the Document Object Model?
When you zoom in, window.innerWidth is adjusted, but document.documentElement.clientWidth is not, therefore:
var zoom = document.documentElement.clientWidth / window.innerWidth;
(I've tested iOS4, without viewport <meta>).
However, I wouldn't rely on it for anything important. DOM viewport sizes/pixel sizes in mobile browsers are a complete mess.
On Mobile Safari and Android, here is an accurate way to measure how much the page has been zoomed.
Try it here: http://jsbin.com/cobucu/3 - change zoom then click measure.
Technique is to add a top level div:
<body>
<div id=measurer style="position:absolute;width:100%"></div>
and use the calculation:
function getZoom(){
return document.getElementById('measurer').offsetWidth / window.innerWidth;
}
The only problem is finding a tidy way to detect that the user has changed zoom (pinch, double tap, etc). Options:
webkitRequestAnimationFrame: very reliable, but likely to cause jankiness if using animations (due to performance hit)
setInterval: reliable but very ugly
touch events: look for two fingers or
double tap: ugly and maybe difficult to make 100% reliable
window.onresize + window.onorientationchange + window.onscroll: simple but totally unreliable (Edit: and onscroll can cause performance problems in WKWebView or Mobile Safari 8 or greater).
PS: Windows Phone needs a different solution (pinch-zoom doesn't change the viewport - pinch-zoom on Windows has its own separate viewport that is not visible to javascript).
Edit: Android Visual Viewport resize and scroll events may help? See https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport#Events
According to the Safari Web Content Guide, zoom events (double tap) are not exposed, so I'm not sure how you can track this.
I do not believe this information is exposed through the DOM.
I actually think things might have moved on a little since Steve's answer, as having a look at the content guide link he provided I can see a section on Handling Multi-Touch Events and also Handling Gesture Events.
Haven't tried them yet but they look pretty promising. I'll provide an update once I've checked them out and have a demo link available...
I measure zoom this way (works on iOS only):
screenOrientedWidth = screen.width;
if (window.orientation == 90) {
screenOrientedWidth = screen.height;
}
return screenOrientedWidth / window.innerWidth;
It doesn't depend of how wide content is.
However, in iOS Safari window.innerWidth isn't correct inside a gestureend handler. You should defer such calculation for later execution. In GWT, I use scheduleDeferred, but I can't say how to implement this in pure JavaScript.
If you are using any elements with location:fixed this can get complicated, as the location:fixed coordinates are relative to the unzoomed window, where window coordinates are relative to the zoomed viewport. More info: How to position a fixed-location element on IOS browser when zoomed?