Not respond on willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration - ios6

I have in code
-(BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation: toInterfaceOrientation duration: duration];
deviceOrientation = toInterfaceOrientation;
if(deviceOrientation == UIInterfaceOrientationPortrait)
{
curPageSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-STATUS_BAR_HEIGHT);
}
else if(deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation == UIInterfaceOrientationLandscapeRight)
{
curPageSize = CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width-STATUS_BAR_HEIGHT);
}
[self correctViews:curPageSize];
}
this methods are defined in ModalViewController...
When i Rotate the device, program is not respond to willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration...
What should i do?!

Try adapting your code to something like this...I have used this method in many Apps with success. Happy coding!
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
//Landscape
self.ViewL.frame = CGRectMake(0, 0, 1024, 728);
self.ViewL.hidden=NO;
self.ViewP.hidden=YES;
}
else
{
//Portrait
self.ViewP.frame = CGRectMake(0, 0, 768, 955);
self.ViewP.hidden=NO;
self.ViewL.hidden=YES;
}
}

Related

How can I use the array that I have at frame 1 to another frame?

When I'm going to draw the next stage at frame 2 my enemies did nothing.
When the stage1 finished I remove the listeners and at stage 2 I add it back.
So, How can I use the array that I have at frame 1 to another frame?
stop();
var enemy1Array:Array = new Array();
for (var e1:int = numChildren - 1; e1 >= 0; e1--)
{
var childe1:DisplayObject = getChildAt(e1);
if (childe1.name.indexOf("enemy")>-1)
{
enemy1Array.push(MovieClip(childe1));
MovieClip(childe1).hitPoints=enemykoufoueshitpoints;
}
}
stage.addEventListener(Event.ENTER_FRAME,loop);
function loop(event:Event):void
{
for(var e:int=enemy1Array.length-1;e>=0;e--)
{
if (playerrun == true)
{
enemy1Array[e].x -=speedall;
}
if (playerrunback == true)
{
enemy1Array[e].x +=speedall;
}
if (enemy1Array[e].hitTestPoint(player.x+5,player.y-40))
{
trace("i heart the player");
zoihit++;
enemy1Array[e].x +=70;
enemy1Array[e].gotoAndPlay(1);
}
if (enemy1Array[e].hitTestPoint(player.x-5,player.y-40))
{
trace("i heart the player");
zoihit++;
enemy1Array[e].x -=70;
enemy1Array[e].gotoAndPlay(1);
}
if (enemy1Array[e].hitTestObject(knife)&&attackright == true)
{
attackright = false;
enemy1Array[e].hitPoints -= knifedamage;
enemy1Array[e].gotoAndPlay(1);
}
if (enemy1Array[e].hitTestObject(knife)&&attackleft == true)
{
attackleft = false;
enemy1Array[e].hitPoints -= knifedamage;
enemy1Array[e].gotoAndPlay(1);
}
if (enemy1Array[e].hitPoints <= 0)
{
var thkiamantoui:thkiamanti= new thkiamanti;
diamondArray.push(thkiamantoui);
this.addChild(thkiamantoui);
thkiamantoui.gotoAndStop(2);
thkiamantoui.x = enemy1Array[e].x;
thkiamantoui.y = enemy1Array[e].y-5.05;
enemy1Array[e].parent.removeChild(enemy1Array[e]);
enemy1Array.splice(e,1);
}
if(enemy1Array[e].hitTestObject(dioswall))
{
enemy1Array[e].parent.removeChild(enemy1Array[e]);
enemy1Array.splice(e,1);
}
}
if(stage2.hitTestObject(playerhit))
{
stage.removeEventListener(Event.ENTER_FRAME,loop);
gotoAndPlay(2);
}
}

How to infinite loop numbers in while loops? (Unity3D- unityscript)

function OnMouseDown () {
rotationNumber +=1;
}
function Update () {
while (rotationNumber == 1) {
gameObject.GetComponent(SpriteRenderer).sprite = leftArrow;
return;
}
while (rotationNumber == 2) {
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
return;
}
while (rotationNumber == 3) {
gameObject.GetComponent(SpriteRenderer).sprite = rightArrow;
return;
}
while (rotationNumber == 4) {
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
rotationNumber = 1;
return;
}
}
I want to loop this but when I click it the fourth time it just goes straight to the first image. I tried yield WaitForSeconds but it didn't work.
The problem is that you are setting rotationNumber to 1 inside the while loop. Do it in this way:
function OnMouseDown () {
rotationNumber += 1;
if ( rotationNumber > 4 ) rotationNumber = 1;
}
function Update () {
while (rotationNumber == 1) {
gameObject.GetComponent(SpriteRenderer).sprite = leftArrow;
return;
}
while (rotationNumber == 2) {
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
return;
}
while (rotationNumber == 3) {
gameObject.GetComponent(SpriteRenderer).sprite = rightArrow;
return;
}
while (rotationNumber == 4) {
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
return;
}
}
I'm not quite sure why you are using a while loop within in an update loop, but try this below. Every time you click the rotation number increases and the sprite is changed until the rotationNumber variable is > 4 in which case it resets the variable back to 1.
function Update()
{
if(rotationNumber == 1)
{
gameObject.GetComponent(SpriteRenderer).sprite = leftArrow;
}else if(rotationNumber ==2)
{
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
}else if(rotationNumber ==3)
{
gameObject.GetComponent(SpriteRenderer).sprite = rightArrow;
}else if(rotationNumber == 4)
{
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
}else if(rotationNumber > 4)
{
rotationNumber = 1;
}
}

UITextView - How to remain cursor after hide keyboard

I'm trying to make a UITextView that user could input text and emoticons.
And I got a problem with the cursor displaying.
My goal is to make the cursor appears as normal while selecting emoticon(Keyboard is hidden).
I know it could be done because a app called "Kakao Story" have the feature.
Does anybody have a solution about it?? Thanks.
I found a way to make keyboardView hidden to access my purpose.
Here is the code
+ (void)hideKeyboard
{
for (UIWindow *aWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *possibleKeyboard in [aWindow subviews]) {
UIView *keyboardView = [self getPeripheralHostViewFromView:possibleKeyboard];
if (keyboardView) {
[keyboardView setHidden:YES];
}
}
}
}
+ (void)unhideKeyboard
{
for (UIWindow *aWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *possibleKeyboard in [aWindow subviews]) {
UIView *keyboardView = [self getPeripheralHostViewFromView:possibleKeyboard];
if (keyboardView) {
[keyboardView setHidden:NO];
}
}
}
}
+ (UIView *)getPeripheralHostViewFromView:(UIView *)superView
{
if ([superView.description hasPrefix:#"<UIPeripheralHostView"]) {
return superView;
}else if([superView.description hasPrefix:#"<UIKBInputBackdropView"]) {
return superView.superview;
}else {
for (UIView *subView in superView.subviews) {
UIView *keyboardHostView = [self getPeripheralHostViewFromView:subView];
if (keyboardHostView) {
return keyboardHostView;
}
}
}
return nil;
}

uikeyboard leaves a black portion on top on navigation

I have a form on the ipad which has many textfield and a button at the end. There are some fields which come under the keyboard when it is active. In order to pull the hidden texfield behind the keyboard to be visible I am using the following code.
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField:textField up:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
_scrollView.frame=CGRectMake(0, 0, 1024, 655);
[self animateTextField:textField up:NO];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
CGPoint temp = [textField.superview convertPoint:textField.frame.origin toView:nil];
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait)
{
// NSLog(#"portrait");
if(up)
{
int moveUpValue = temp.y+textField.frame.size.height;
animatedDis = 264-(1024-moveUpValue-5);
}
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown)
{
if(up)
{
int moveUpValue = 1004-temp.y+textField.frame.size.height;
animatedDis = 264-(1004-moveUpValue-5);
}
}
else if(orientation == UIInterfaceOrientationLandscapeLeft)
{
if(up)
{
int moveUpValue = temp.x+textField.frame.size.height;
animatedDis = 352-(768-moveUpValue-5);
}
}
else
{
if(up)
{
int moveUpValue = 768-temp.x+textField.frame.size.height;
animatedDis = 352-(768-moveUpValue-5);
_scrollView.frame = CGRectMake(0, 0, 1024, 655-240);
}
}
if(animatedDis>0)
{
const int movementDistance = animatedDis;
const float movementDuration = 0.3f;
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: nil context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
if (orientation == UIInterfaceOrientationPortrait)
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
else if(orientation == UIInterfaceOrientationLandscapeLeft)
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
else
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
[UIView commitAnimations];
}
}
I am also using the scroll view. My issue is that when the keyboard is active and i press my button it take me to the next screen. Now if i navigate back, the keyboard is active and the prior animations are set. Now if i hide the keyboard, the entire view scrolls down leaving a black portion on top. How to handle this situation?
Okay. After much research I found a simple method. It is the use of notifications.
In my viewDidLoad i added these two keyboard notifications.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWasShown:) name: UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
These are the 2 selector methods:
-(void)keyboardWasShown:(NSNotification *)aNotification
{
if (displayKeyboard==YES) {
return;
}
NSDictionary* info = [aNotification userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
//NSValue* aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
NSLog(#"kbw====%fkbh====%f",keyboardSize.width,keyboardSize.height);
offset = _scrollView.contentOffset;
CGRect viewFrame = _scrollView.frame;
NSLog(#"svw====%fsvh===%f",viewFrame.size.width,viewFrame.size.height);
viewFrame.size.height -= keyboardSize.height-49;
NSLog(#"new view hgt =====%f",viewFrame.size.height);
_scrollView.frame = viewFrame;
CGRect textFieldRect = [activeField frame];
textFieldRect.origin.y += 10;
[_scrollView scrollRectToVisible: textFieldRect animated:YES];
displayKeyboard = YES;
}
-(void)keyboardWillBeHidden:(NSNotification *)aNotification
{
if (!displayKeyboard) {
return;
}
_scrollView.frame = CGRectMake(0, 0, 1024, 655);
_scrollView.contentOffset =offset;
displayKeyboard = NO;
}
-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField {
activeField = textField;
return YES;
}
displayKeyboard, offset and activeField are declared in .h file.
Also remember to remove the notifications in viewDidDisappear:animated
Although this method is quite different than the previous one stated, this one does not leave a black portion on the top while navigating between classes when the uikeyboard is active.
Also what i noticed was if i used the deprecated UIKeyboardBoundsUserInfoKey i used to get the correct width and height of the keyboard(i am working only in landscape mode). Whereas when i used UIKeyboardFrameBeginUserInfoKey the width and height values were interchanged. I am still trying to figure out this problem.
Also when the keyboard used to appear, a fixed space of 49px was appended to above it. I assumed that that was my tabbar height and therefore subtracted 49.

For each string in Array

Just as the name says, I want that for each certain name in an array a value is added to a int.
For example: if there are 3 strings of the same name in the array, then 3 times 50 will be added to the value.
This is my script I have now:
var lootList = new Array();
var interaction : Texture;
var interact = false;
var position : Rect;
var ching : AudioClip;
var lootPrice = 0;
function Update()
{
print(lootList);
if ("chalice" in lootList){
lootPrice += 50;
}
}
function Start()
{
position = Rect( ( Screen.width - interaction.width ) /2, ( Screen.height - interaction.height ) /2, interaction.width, interaction.height );
}
function OnTriggerStay(col : Collider)
{
if(col.gameObject.tag == "loot")
{
interact = true;
if(Input.GetKeyDown("e"))
{
if(col.gameObject.name == "chalice")
{
Destroy(col.gameObject);
print("chaliceObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("chalice");
}
if(col.gameObject.name == "moneyPouch")
{
Destroy(col.gameObject);
print("moneyPouchObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("moneyPouch");
}
if(col.gameObject.name == "ring")
{
Destroy(col.gameObject);
print("ringObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("ring");
}
if(col.gameObject.name == "goldCoins")
{
Destroy(col.gameObject);
print("coldCoinsObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("goldCoins");
}
if(col.gameObject.name == "plate")
{
Destroy(col.gameObject);
print("plateObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("plate");
}
}
}
}
function OnTriggerExit(col : Collider)
{
if(col.gameObject.tag == "pouch")
{
interact = false;
}
}
function OnGUI()
{
if(interact == true)
{
GUI.DrawTexture(position, interaction);
GUI.color.a = 1;
}
}
It's for a game I'm making where you can steal items for extra score points.
I've tried using the for(i = 0; i < variable.Length; i++) but that didn't seem to work.
The only thing I can think of now is using booleans to add it once. But that isn't memory friendly.
Help is appreciated and thanks in advance!
You could use the standard .forEach(callback) method:
lootList.forEach(function(value, index, array)
{
if (value === "chalice") { lootPrice += 50; }
});
If you don't have that method, you could implement it like this:
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (callback) {
for(var i = 0; i < this.length; i++) { callback(this[i], i, this); }
}
}

Resources