Code Snippet: While loops (PHP)

No Comments

If you want to organise or display data on a website, the best way is the php function ‘while’. Example of usage:

$i = 0;

while($i <= 6) {

echo $i;

$i++;

}

This code prints out the numbers 0 through 6 (0123456). Advancing this, you could have an array with 3 values in, and call them up like this:

$array = array('one', 'two', 'three');

$i = 0; // Remember Arrays start at 0

while($i <= 2) { // After I reaches 2, this loop stops - that gives the three values

echo $array[$i];

echo "<br>"; // html code for line break

$i++;

}

This code gives the following output:

one

two

three

I’ll advance on this later, but for now – it’s late.

Code Snippet: Getting the current frame of a UIViewAnimation

No Comments

I’ve got this information whilst coding Navigate Nigel. The issue I was having was when checking for the current frame of a UIImageView, it would return the end point of the UIViewAnimation. This is because Core Animation sets the frame to the end point, then deals with the animation. To get round this, it’s just one bit of code. In the code, I have named the object I am checking the frame for as “view” – this could count for any object in your application.

[[view.layer presentationLayer] frame]

And that’s all!