If Then

Discussion in 'iOS Programming' started by Programmer, Aug 31, 2009.

  1. Programmer macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #1
    I am creating a game where you tap a character when he appears. I have UIImageViews set up with buttons over them is there a way to say that only if the image is being displayed that the button will be pushed?
     
  2. Kingbombs macrumors member

    Joined:
    Jun 24, 2009
    #2
    Set a BOOL value so BOOL imageAppeared = NO;
    then when the image has appeared set imageAppeared = YES;

    then in the IBAtion for the button have at the start
    if (imageAppeared) { // so if the imageAppeared is YES Then:
    //code to do what ever you want here
    }
     
  3. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
  4. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #4
    But...

    what would the BOOL be like with the Auto Rotation of the interface

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
     
  5. Kingbombs macrumors member

    Joined:
    Jun 24, 2009
    #5
    Not sure quite what you mean,
    That method return's yes if it should auto rotate to the orientation specificed (default code will say only vertical), but if you specify orientationLeft then when you rotate it left, it will return yes and rotate it, if you haven't specificed it then when you rotate the phone it will call that method and return no and not change the view in any way

    if you want to check which way the phone is position example the home button is at the bottom, on the left, right or up top
    then maybe create an NSIntger, and give it a number depending on the direction it is being held, 0 is vertical, 1 is left, 2 is right etc
    then just check what that number is when you need to do something if its held in a certain way

    as i said not sure quite what you meant so said what the method does, and what i think you may have asked
     
  6. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #6
    I didn't mean that

    Sorry for the mix up. I was using that as an example i was asking how do you set up the BOOL like do i say -(BOOL)ImageAppeared; in the .h and say
    -(BOOL)ImageAppeared = NO in the .m and so on so forth?
     
  7. Kingbombs macrumors member

    Joined:
    Jun 24, 2009
    #7
    in the .h do
    BOOL imageAppeared;

    then in the .m viewdidLoad or where ever you initalise everything:
    imageAppeared = NO;

    then just change it like that throughout:
    imageAppeared = YES
    or to use it in an if statement: if (imageAppeared) or if(imageAppeared == YES)
     

Share This Page