Posted: April 15th, 2010 | Author: admin | Filed under: Objective-C | Tags: iPhone, Navigation Bar, Objective-C, Segmented Button | 3 Comments »
We can change the buttons on a navigation bar on the left and right sides, but how do we add a button in the middle of the Navigation Bar? The trick is to use the “titleView” property of navigationItem, and to assign it the customView of our just created segmented control. For more clarity look at the code below. Feel free to comment!
-
-
NSArray *itemArray = [NSArray arrayWithObjects: @"All", @"Some", nil];
-
chooseAllORSome = [[UISegmentedControl alloc] initWithItems:itemArray];
-
chooseAllORSome = CGRectMake(0,0,150, 32);
-
chooseAllORSome.segmentedControlStyle = UISegmentedControlStyleBar;
-
chooseAllORSome.selectedSegmentIndex = 0;
-
[chooseAllORSome addTarget:self action:@selector(pickOne:) forControlEvents:UIControlEventValueChanged];
-
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView: chooseAllORSome];
-
self.navigationItem.titleView = segmentBarItem.customView;
-
self.navigationItem.title = @"";
-
[segmentBarItem release];
-
Posted: April 7th, 2010 | Author: admin | Filed under: Objective-C | Tags: iPhone, Objective-C, Rotate | No Comments »
When adding subviews to a superview doing addSubview and then bringSubviewToFront, I have found that subviews do not autorotate accordingly, therefore I needed to do it programmatically. The next piece of code does a landscape rotation of a UIView to the left or to the right. Note that the UIView has to be resized and located accordingly. For that, I set up the bounds to 480×320 because I always expect a +90 or -90 degrees rotation.
-
-
#define DegreesToRadian(__ANGLE__) ((__ANGLE__) / 180.0 * M_PI)
-
-
void rotateLandscape(UIView *viewToRotate, BOOL left) {
-
viewToRotate.transform = CGAffineTransformIdentity;
-
if (left) viewToRotate.transform = CGAffineTransformMakeRotation(DegreesToRadian(-90));
-
else viewToRotate.transform = CGAffineTransformMakeRotation(DegreesToRadian(+90));
-
viewToRotate.bounds = CGRectMake(0.0, 0, 480, 320);//resize the view
-
viewToRotate.center = CGPointMake(160.0f, 240.0f); //set the position of the view
-
}
-
An example on how to use it is:
-
rotateLanscape(appDelegate.mapController.view,TRUE);
The second common action, dealing with UIViews’ transitions on iPhone development, is to be able to set up an animation in the transition between views. The next code do that:
-
void setUpAnimation(UIView *animateWindow, UIViewAnimationTransition transitionType, float duration) {
-
-
[UIView beginAnimations:@"Animation" context:nil];
-
[UIView setAnimationDuration:duration ];
-
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
-
[UIView setAnimationTransition: transitionType forView:animateWindow cache:YES];
-
[UIView commitAnimations];
-
}
An example on how to use it is:
-
setUpAnimation(appDelegate.window, UIViewAnimationTransitionCurlDown, 0.5);
Embedding these two actions into functions sounds like a good idea since they will be repeated throughout your application many times. Also these are basic versions, they could allow more complex animations and rotations but I leave that for another day.
Posted: February 2nd, 2010 | Author: admin | Filed under: Objective-C | No Comments »
As a general rule, learning a programming language is not such a big deal for an experienced programmer. It’s just a matter of being the language syntax reference on hand and understanding the language philosophy, such as, object oriented, procedural, structured, logical, event-driven, etc. However, that hasn’t been my case for Objective-C.
Objective-C implements quite a few different concepts if we compare it with C, C++, Visual Basic, Fortran, Cobol, Perl, PHP and so on.
In my first approach to Objective-C over the past few weeks I have to say that it looks like such a powerful language, well thought and mature, but it requires quite a bite of time to become familiar with it. Perhaps I was not ready for it.. and the learning curve has been steeper than expected.
Delegation, message sending and its expressive message syntax have been the toughest things to be understood so far.
So, it’s not fun but very promising instead.. some experience opinion would be appreciated!
Good Tutorials and sample code for a beginner level can be found at:
http://www.lynda.com/home/DisplayCourse.aspx?lpk2=48369
http://www.appsamuck.com/
Posted: December 31st, 2009 | Author: admin | Filed under: General | 1 Comment »
Beside what most people might think, each piece of code is unique and, most importantly, it reflects the programmer’s way of approaching problems, it shows great part of his/her personality. Throughout the source code and comments included in this Blog, I would like to show how creative and excitement writing computer applications can be, and how is it like to be in continuous relation with computers.