в оболочке, время моего сервера (простая дата
в bash):
Легко - просто добавьте код в willAnimateRotationToInterfaceOrientation: callback - (void) ...
В MainViewController мне нужно настроить некоторые изображения при изменении ориентации. Легко - просто добавьте код в willAnimateRotationToInterfaceOrientation: обратный вызов
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
NSLog(@"orientation: %@", name(orientation));
..
Работает, как ожидалось. Находясь в портретной ориентации, я нажимаю UIViewController с другой ориентацией на UINavigationController. Я перехожу в режим «Пейзаж», и все в порядке.
Затем я возвращаюсь к MainViewController, вызывая
[self.navigationController popViewControllerAnimated:YES];
. В то время как подпредставления MainViewController настраиваются на «Пейзаж» в соответствии с масками автоматического изменения размера, willAnimateRotationToInterfaceOrientation: не работает. звоните!
Я ожидал willAnimateRotationToInterfaceOrientation: g 71 элемент?
// the variables
$array = array("a", "b", "c", "d");
$desiredLength = 71;
$newArray = array();
// create a new array with AT LEAST the desired number of elements by joining the array at the end of the new array
while(count($newArray) <= $desiredLength){
$newArray = array_merge($newArray, $array);
}
// reduce the new array to the desired length (as there might be too many elements in the new array
$array = array_slice($newArray, 0, $desiredLength);
Простое решение с использованием each()
и reset()
и внутреннего указателя массива:
<?php
$array = array('a', 'b', 'c', 'd');
$length = 71;
$result = array();
while(count($result) < $length)
{
$current = each($array);
if($current == false)
{
reset($array);
continue;
}
$result[] = $current[1];
}
echo count($result); // Output: 71
Если у вас доступен PHP 5.3, вы также можете попробовать это:
function fill(array $initalArray, $toCount) {
$initialArrayCount = count($initalArray);
$fillUp = function(array $filledUpArray, $missingCount)
use(&$fillUp, $initalArray, $initialArrayCount, $toCount)
{
if($missingCount <= 0) return array_slice($filledUpArray, 0, $toCount);
return $fillUp(array_merge($filledUpArray, $initalArray), $missingCount - $initialArrayCount);
};
return $fillUp($initalArray, $toCount - $initialArrayCount);
}
$theArray = array("a", "b", "c", "d");
$toLength = 71;
$filledArray = fill($theArray, $toLength);
print_r($filledArray);
$newarray = array();
$i = 0;
$oldarrayvalues = array_values($oldarray);
$oldarraysize = count($oldarrayvalues);
if ( $oldarraysize ) {
while ( count($newarray) < DESIRED_ARRAY_SIZE ) {
$newarray[] = $oldarrayvalues[$i];
$i++;
$i %= $oldarraysize;
}
}
Решение с использованием SPL InfiniteIterator:
<?php
function fillArray1($length, $values) {
foreach (new InfiniteIterator(new ArrayIterator($values)) as $element) {
if (!$length--) return $result;
$result[] = $element;
}
return $result;
}
var_dump(fillArray(71, array('a', 'b', 'c', 'd')));
Настоящие хакеры SPL могли сбросить if (!$ length--) break;
и вместо этого использовал предельный итератор: new LimitIterator(new InfiniteIterator(new ArrayIterator($values)), 0, $length)
, но я подумал, что это перебор. ..
$array = array("a", "b", "c", "d");
$merge = array();
$desiredLength = 71;
while(2 * count($array) <= $desiredLength){
$array = array_merge($array, $array);
}
if($desiredLength > count($array))
$merge = array_slice($array, 0, $desiredLength - count($array));
$array = array_merge($array, $merge);
$array = array_slice($array, 0, $desiredLength);
print_r($array);