iPhone iOS4 block animation woes

I have been working with the new block-based animations that came with the iOS4 update. It’s pretty interesting what blocks can do.

Here is a little information on the animations for views, though.

The default options for running animations seemed to have changed.

I was converting an animation of a view that ran in my touchesBegan function. I encountered a problem with my animation not calling touchesEnded if the touch event ended before the animation.

After hours of forum searching and a day to rest, I found out that the default options have changed.

To change options you must invoke the

animateWithDuration:delay:options:animations:completion:

function and add options that can be found in the documentation.

For my error in particular, the option UIViewAnimationOptionAllowUserInteraction was needed so that the view could received user interaction while being animated.

I hope this short post helps. I know it would have prevented my head from exploding if I had found it.

Patrick

Differences between Objective C and C/C++: functions

So you’re a C/C++ programmer and want to enter the wonderful world of Objective C. Well you have come to the right place for that. This tutorial will cover some of the differences between the language of C and Objective C for functions. I will add subsequent tutorials for the other parts later. A lot of it is straight forward but some might seem like glass candy. So let’s jump right into it.

Functions:
Functions in Objective C tend to be quite different syntactically than in C/C++. The general concepts are still the same though.

1. declaration
- (returnType) functionName:(paramType)paramName paramIdentifier:(paramType2)paramName2;
Above is an generic function declaration in Objective C. It might seem a little confusing. especially when you get to function parameters, but we will take this thing apart piece by piece.

- (returnType) functionName:(paramType)paramName paramIdentifier:(paramType2)paramName2;
The first thing to notice is the “-” at the beginning. This says that the function will be an instance method. A class method would be denoted with a “+” instead.

- (returnType) functionName:(paramType)paramName paramIdentifier:(paramType2)paramName2;
Next comes the return type. In objective C you must contain it within parentheses. Pretty simple…

- (returnType) functionName:(paramType)paramName paramIdentifier:(paramType2)paramName2;
Next the function name which is the same as in C.

- (returnType) functionName:(paramType)paramName paramIdentifier:(paramType2)paramName2;
Here is where things get a little tricky. The colon after the function name denotes that a parameter is coming up next. The type is contained in parentheses and then the name comes after.

- (returnType) functionName:(paramType)paramName paramIdentifier:(paramType2)paramName2;
Subsequent parameters use a space as a seperater instead of a comma and have a parameter identifier. This is used for when you call a function which will be explained later. Then like the first parameter the colon and parameter type and parameter name follow.

Make note that the parameter identifier for the first parameter will be the function name. So, it is sometimes useful to add information on the end of the function name. For example, you could say functionNameWithParameter as the function name.

NOTE:
But what if our functions don’t have parameters? Well this is very simple, but can trip C programmers up. Since we don’t use parentheses to house our parameters there is no need to add the obligatory “()” at the end of the function as we would in C. The function without parameters is just,
- (returnType) functionName;

2. Definition
Alright, function declarations down, let’s move on to definitions. You will be surprised with the differences between the declaration and definition.

- (returnType) functionName:(paramType)paramName paramIdentifier:(paramType2)paramName2
{
//your code here
}

Above is a generic function definition in Objective C. Wait, there is nothing different here at all. Surprise, it’s exactly like the declaration except you have curly brackets and your code just like you would in C.

Again, something to note is that paramIdentifier is only used when calling a function. If you wanted to reference a parameter inside your function you would use paramName or paramName2.

3. Calling functions
Unfortunately there are some changes between calling functions in c and calling functions in objective c.

[classObject functionName:param1 paramIdentifier:param2];
Above is a generic function call in Objective C. Well, that is quite different. Lets pick this sucker apart.

[classObject functionName:param1 paramIdentifier:param2];
The first thing to take note of is that you will always be surrounding your function call with square brackets.

[classObject functionName:param1 paramIdentifier:param2];
Second is the object. Since we are working with class structures we need to know where this function is located that we are calling.

NOTE:
If you are calling the function inside of the class you instantiated it in then you would use the objective c object “self”.

[object functionName:param1 paramIdentifier:param2];
Next we come up to the function name which is just like the declaration.

[object functionName:param1 paramIdentifier:param2];
Here is that colon that we saw after the function name in the declaration. It also denotes that a parameter is coming up. This is like C in that you put the parameter you want to pass here.

[object functionName:param1 paramIdentifier:param2];
Now here is that parameter identifier I mentioned earlier. This is used to help the caller of the function know what to put there. After the colon you will again place your parameter.

Conclusion
There might be other quirks that arent mentioned here, but overall that is the gist of functions in objective c. I hope this tutorial helped, and feel free to give me suggestions (especially since this is my first tutorial) or let me know if there are corrections that need to be made.

Patrick

Contracted Work

Hello everyone,
I know it’s been awhile, but we’ve really been busy here at SGS. We are about to finish up a big project that we’ve been working on, and move on to the Equater Content patch (spoiler alert: the patch includes openfeint support).
Anyway, what I’m specifically posting about, is that we are formally opening our doors to outside app requests. Do you have an idea that you know will sell, or do you just want your idea on the app store? Well, we can help. Soon, we’ll put up a better way for you to contact us, but for now you can contact me directly at mtg533[at]gmail[dot]com.
Thanks for all the support,
SGS Staff

DropBox!!

This is really just a “Hey look what we found” post. Have you ever collaborated with a team? Had to send files back and fourth? You probably used gmail right? Yeah, so did we, but that gets cumbersome. So Patrick found Dropbox which is a FREE and easy file sharing tool. Really it’s very simple and useful. So, if you are collaborating with a team, or just need a easy way to store some files between personal computers, check it out.
And if you want to be really nice, let me refer you so I can get some extra space! Referal Link

The Start of Something Great

Hello Everyone!

You’ve made it to the SGS Dev blog. Most of what will be posted here will be about up coming projects, additions to existing projects, or just other things that our developers find worthy of a blog post. So check back for inside information on what is going on at SGS.