This snippet comes to mind from time to time – one easy way to divide a rectangle into smaller rectangles- I actually went back and looked it up as it was an answer to a student question from 2006. The original one was written in ActionScript 2. Have a look:
var wormNum:Number=123;
var wormCount:Number=0;
newWorm(400,400,0,0);
this.onEnterFrame=function(){
if(wormCount < wormNum){
for(var props:Stringinthis){
if(this[props]._x !=undefined){
this[props].divide();
}
}
}
};
function newWorm(w, h, xp, yp){
var currWorm:MovieClip =this.createEmptyMovieClip("box"+wormCount,this.getNextHighestDepth());
With IOS 16 all my apps that support multiple orientations are now broken when rotating the device. Apple has broken my apps so many times with stuff like this. It’s so frustrating! Anyway…
Here is how I fixed it for my apps. In my main view controller I listen for orientation changes:
That has been that way for years… works fine and calls orientationChange.
-(void)orientationChange:(NSNotification *)note {
UIDevice * device = note.object;
orient = device.orientation;
// found this by searching around github https://github.com/liLeiBest/LZDependencyToolkit/blob/bca976207ef9674632d448e62ac425c22cecbc4f/LZDependencyToolkit/Classes/Category/UIViewController+LZForceRotation.m#L107
That big blob checking if IOS 16 is available is now necessary. Within my refreshUI method I use the width and height of the screen to position things. It seems that [[UIScreen mainScreen] bounds].size.height now takes a few hundred milliseconds to be updated with the current orientation. Maybe there is some new animation that needs to be disabled, but I have not been able to find it. So, I just delay 200ms and all seems ok:
In vanilla js you’ll find yourself checking if an HTML DOM element can be removed, by seeing if it has a parent (as seen above). Forgetting to do so is the source of many errors.
With the death of IE11 you can use remove()
const button = document.createElement('button');
button.innerText='Hello There 2';
document.body.appendChild(button);
// click anywhere
document.body.addEventListener('click',()=>{
button.remove();
});
No error occurs when calling remove() on something that is already removed… just like the old jQuery days 😉