Sign in to follow this  

[Answered] Why is rescaling in standalone web app broken in iOS10?

Recommended Posts

Using Animate CC, with publish settings set to make responsive = both, center = both, scale to fill visible area = fit in view, like this:


In mobile Safari, everything works out well, the canvas resizes as normal when screen orientation changes. When saved to Home Screen as standalone web app though, the canvas isn't resizing after changing to a smaller size, like this:


Here's the full html code generated by Animate CC:

<!DOCTYPE html>
	1. All tokens are represented by '$' sign in the template.
	2. You can write your code only wherever mentioned.
	3. All occurrences of existing tokens will be replaced by their appropriate values.
	4. Blank lines will be removed automatically.
	5. Remove unnecessary comments before creating your template.
<meta charset="UTF-8">
<meta name = "viewport" content = "width=device-width,initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="authoring-tool" content="Adobe_Animate_CC">
<!-- write your code here -->
  #animation_container {
<script src=""></script>
(function (cjs, an) {
var p; // shortcut to reference prototypes
var lib={};var ss={};var img={};
lib.ssMetadata = [];
// symbols:
// stage content:
(lib.testView = function(mode,startPosition,loop) {
}).prototype = p = new cjs.MovieClip();
p.nominalBounds = null;
// library properties: = {
	id: '035086AC98814BD6A0BA64225202ABA0',
	width: 400,
	height: 550,
	fps: 24,
	color: "#3366FF",
	opacity: 1.00,
	manifest: [],
	preloads: []
// bootstrap callback support:
(lib.Stage = function(canvas) {, canvas);
}).prototype = p = new createjs.Stage();
p.setAutoPlay = function(autoPlay) {
	this.tickEnabled = autoPlay;
} = function() { this.tickEnabled = true; this.getChildAt(0).gotoAndPlay(this.getTimelinePosition()) }
p.stop = function(ms) { if(ms); this.tickEnabled = false; } = function(ms) { this.tickEnabled = true; this.getChildAt(0).gotoAndStop( * ms / 1000); }
p.getDuration = function() { return this.getChildAt(0).totalFrames / * 1000; }
p.getTimelinePosition = function() { return this.getChildAt(0).currentFrame / * 1000; }
an.bootcompsLoaded = an.bootcompsLoaded || [];
if(!an.bootstrapListeners) {
an.bootstrapCallback=function(fnCallback) {
	if(an.bootcompsLoaded.length > 0) {
		for(var i=0; i<an.bootcompsLoaded.length; ++i) {
an.compositions = an.compositions || {};
an.compositions['035086AC98814BD6A0BA64225202ABA0'] = {
	getStage: function() { return exportRoot.getStage(); },
	getLibrary: function() { return lib; },
	getSpriteSheet: function() { return ss; },
	getImages: function() { return img; }
an.compositionLoaded = function(id) {
	for(var j=0; j<an.bootstrapListeners.length; j++) {
an.getComposition = function(id) {
	return an.compositions[id];
})(createjs = createjs||{}, AdobeAn = AdobeAn||{});
var createjs, AdobeAn;
var canvas, stage, exportRoot, anim_container, dom_overlay_container, fnStartAnimation;
function init() {
	canvas = document.getElementById("canvas");
	anim_container = document.getElementById("animation_container");
	dom_overlay_container = document.getElementById("dom_overlay_container");
	var comp=AdobeAn.getComposition("035086AC98814BD6A0BA64225202ABA0");
	var lib=comp.getLibrary();
function handleComplete(evt,comp) {
	//This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
	var lib=comp.getLibrary();
	var ss=comp.getSpriteSheet();
	exportRoot = new lib.testView();
	stage = new lib.Stage(canvas);	
	//Registers the "tick" event listener.
	fnStartAnimation = function() {
		createjs.Ticker.addEventListener("tick", stage);
	//Code to support hidpi screens and responsive scaling.
	function makeResponsive(isResp, respDim, isScale, scaleType) {		
		var lastW, lastH, lastS=1;		
		window.addEventListener('resize', resizeCanvas);		
		function resizeCanvas() {			
			var w =, h =;			
			var iw = window.innerWidth, ih=window.innerHeight;			
			var pRatio = window.devicePixelRatio || 1, xRatio=iw/w, yRatio=ih/h, sRatio=1;			
			if(isResp) {                
				if((respDim=='width'&&lastW==iw) || (respDim=='height'&&lastH==ih)) {                    
					sRatio = lastS;                
				else if(!isScale) {					
					if(iw<w || ih<h)						
						sRatio = Math.min(xRatio, yRatio);				
				else if(scaleType==1) {					
					sRatio = Math.min(xRatio, yRatio);				
				else if(scaleType==2) {					
					sRatio = Math.max(xRatio, yRatio);				
			canvas.width = w*pRatio*sRatio;			
			canvas.height = h*pRatio*sRatio; = = =  w*sRatio+'px'; = = = h*sRatio+'px';
			stage.scaleX = pRatio*sRatio;			
			stage.scaleY = pRatio*sRatio;			
			lastW = iw; lastH = ih; lastS = sRatio;            
			stage.tickOnUpdate = false;            
			stage.tickOnUpdate = true;		
<!-- write your code here -->
<body onload="init();" style="margin:0px;">
	<div id="animation_container" style="background-color:rgba(51, 102, 255, 1.00); width:400px; height:550px">
		<canvas id="canvas" width="400" height="550" style="position: absolute; display: block; background-color:rgba(51, 102, 255, 1.00);"></canvas>
		<div id="dom_overlay_container" style="pointer-events:none; overflow:hidden; width:400px; height:550px; position: absolute; left: 0px; top: 0px; display: block;">

On an iOS9 device, it seems to be working well. How to do update Animate CC's rescaling code so that it works in iOS10 (and above)?

Share this post

Link to post
Share on other sites

Strangely enough, when I added this code, and my iOS device has that blue header (for personal hotspot), the standalone web app scales back bigger as normal when the screen orientation changes. It only works in hotspot mode though.

window.addEventListener("orientationchange", function () {
			document.width = window.screen.width;


Share this post

Link to post
Share on other sites

Anyone has any ideas why the responsive code doesn't work?

Because Safari is the new IE6.

Seriously, I've had a group of developers waste a load of time on inaccuracies in Safari like this one, with very mixed success. There are so many little problems with developing for Safari.

The blue hotspot 'banner' is often invisible to the web, ditto for the task bar at the bottom. Dealing with either is not good, in fact, I'm not convinced you _can_ even deal with the hotspot bar effectively, although, as you've noted, different versions manifest different bugs/inaccuracies so maybe it is more accurate to say that you can't fix things for all your users all in one go; i.e. you have to pick the _least_ annoying problem and some users will just have to live with it, either the least annoying problem or the smallest sub-set of users.

Something you could check though, that might help:

*Check when resize fires*

I think that it can be a little inconsistent (across versions) i.e. sometimes it fires early and you'll be measuring the screen _before_ the resize, sometimes it'll fire late, in your case it sounds like maybe it is firing early and you aren't measuring the screen dimensions you think (and want to be) you are.

The only solution for this _early_ firing is to use a small timeout. Of course you don't want to fire it too early and you don't know when the screen will _actually_ rotate so you have to give it a bit more delay than you think, which will be 'flashy' for users, and using timeouts for this stuff is always dangerous because there might be some processing that delays rotation and you get it wrong. You _could_ try to work out the ratio and try to keep track of landscape/portrait to see if you're checking the correct orientation change, but, if you get this wrong (i.e. when the user rotates a lot) then you could get really stuck.

Share this post

Link to post
Share on other sites

I see, perhaps a delay would be a good idea. Using this?

        <code here>
    }, 5000);

Should I put it inside function resizeCanvas()? With the rest of it's code inside the setTimeout function?

Update: You were right, mattstyles. After putting a setTimeout function to delay the resizeCanvas function, the canvas is now scaling properly. Instead of 5000, I put 20, because it seems to work instantaneously at that lower value.

If anyone has a better idea how to implement it, please let me know. Thanks so much!

Share this post

Link to post
Share on other sites

@trial asked me on PM how we manage to solve this issue on our games.  I've replied here so anyone else experiencing the same issue may benefit.  Simple answer is to run the resizeCanvas check almost continuously (on update / RAF tick).

Compare a concatenation of window.innerWidth and window.innerHeight to the previous state, if it's the same ignore, if it's different then recompute the resize / css scaling and offsets.  We make no use of any Events for this, which may seem less than efficient but we found Events to be inconsistent (and the overhead of continuous comparison to be minimal).  This analysis was originally done ~2012 so things may have improved since (and other things may have worsened) - but the code from our framework written mostly at that time can be seen here:

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.