tags:

views:

38

answers:

3

I want to make a selection before apply one of two animations, what I thought is: make a Piont "one", if my "myImageView" is at the Point "one", then apply animationNo1, else apply animationNo2, but I got this:"used struct type value where scalar is required", at line "if (myImageView.layer.position = one) " What I do? how can I fix this? Does anyone know exactly what makes the problem happen? Thank you, very much.

 CGPoint one = CGPointMake(myImageView.layer.position.x, 100);

 if (myImageView.layer.position = one) 
 {
       animationNo1
 }

 else 
 {
       animationNo2
 }
+2  A: 

if (myImageView.layer.position = one) { animationNo1 }

should be

if (CGPointIsEqualToPoint(myImageView.layer.position, one)) { animationNo1 }

You used a single = meaning assignment, rather than a == for comparison. But the == wouldn't do what you wanted here anyway.

Joshua Weinberg
thank you for remind me to use == to compare, CGPointEqualToPoint works great! it should be CGPointEqualToPoint, without "Is" in the middle
flutewang
Thats what I get for typing in functions without checking the docs :)
Joshua Weinberg
+3  A: 

First of all, your if-statement will not do what you think. If you want to compare something you have to use == (ie 2 =)

and you can't compare CGPoints like this.

use

 if (CGPointEqualToPoint(one, self.view.layer.position))
fluchtpunkt
I tried CGPointEqualToPoint to compare, it works fine, Thank you :)
flutewang
and also thx for using == to compare!
flutewang
@flutewang: You should accept his answer out to thank him for his help.
thyrgle
+1  A: 

You are passing a struct (int this case position) instead of a scalar. To do what you want you need to use CGPointIsEqualToPoint:

if (CGPointEqualToPoint(one, self.view.layer.position))

Full code with corrections:

CGPoint one = CGPointMake(myImageView.layer.position.x, 100);

if (CGPointEqualToPoint(one, self.view.layer.position))
{
      animationNo1
}

else 
{
      animationNo2
}

Also, as others have pointed out: Be careful about = vs ==. They are different. In this case you don't use == for comparison fortunately, but if you use = for other stuff it will make it true instead of checking to see if it is true.

thyrgle
thanks, thyrgle, i carry lots of ideas to start programming, it's tough to achieve what I'm thinking, seems i need to browse more dictionaries from apple and the language itself, thank you guys! you are all very kind! :)
flutewang