Tuesday, 30 August 2011

XCode 4 says "requires Max OS X 10.6.6" when tried to install on Lion

You got to be kidding me... Tried to install XCode 4 on Lion (10.7.1), and it says "iPhone SDK requires Max OS X 10.6.6 - to install the iOS SDK you must quit the installer and upgrade to Max OS X 10.6.6"...

Yeah right, luckily Apple now offers XCode 4.1 for Lion free - I guess this is another incentive to encourage all developers to upgrade to Lion?

Only trouble is, another huge 4GB download...

MacFuse doesn't work on OS X Lion??

Just received my new 13" MacBook Pro - running OS X 10.7.1 Lion. Was installing NTFS-3G plus MacFuse on it to access my NTFS external UBS drives.

But I keep getting this error as shown below: "dyld: Library not loaded: /usr/local/lib/libfuse.2.dylib Reference from: /usr/local/bin/ntfs-3g Reason: image not found"

When I then check the status of MacFuse it says "MacFUSE does not appear to be installed" and can't check for Updates.

Did some search and found this post saying:

The original MacFUSE project is no longer under development. Amit, the
author, has moved on to a closed source version [NuFS] that you can license.
There are a variety of updates to this code base that have been distributed
to get support for Lion and 64-bit Snow Leopard, use them at your own risk.

OSXFUSE [https://github.com/osxfuse/]:
This is a direct descendent of MacFUSE being lead by Erik Larsson and
Benjamin Fleischer - it properly supports Lion [as of the 2.3 branch] and is
actively developed. It should largely "just work" if you're already using
MacFUSE. You can download it from Github - presumably future releases will
live at http://osxfuse.github.com

Fuse4X [http://fuse4x.org/]:
MacFUSE is notably "not fuse" - in that largely mimics but does not
replicate FUSE interface on Linux. Fuse4X descends from MacFUSE but aims to
"be fuse" for the Mac and given that, it no longer stands as a pure
replacement for MacFUSE - but intends to provide a MacFUSE compatibility
layer eventually. It is being actively developed by Anatol Pomozov

Great, will need to learn about this new thing called "OSXFUSE" then, hope it's not too complicate/difficult...

[Update] The unofficial package mentioned in this post which points to this download seems to work for me. Although at the beginning it reports an error about not getting response within 15 seconds...

[Update 2] Thanks to info from "anonymous" (See below), I applied the workaround following the information from https://gist.github.com/1100318 and I now no longer gets that 15 second error. Thanks!

Saturday, 27 August 2011

Neon Label Test

Saw quite a lot of games using fancy label/text/drawings with nice "neon" effect. Searched on the net for a while and found 2 sites ( Cocoanetics and stackoverflow.com info by Brad Larson) which have some useful information. So I combined the 2, plus some colour info from Visibone, and I was able get some nice labels with Neon effect working.

But I think that's not enough. Mainly because the effect of these neon labels will also depend on the background colour/image underneath.  So I modified one of my old projects (the "project#2" mentioned in this post, based on Chapter 7 example code from the iPhone Application Development for iOS4 Visual QuickStart guide book) a bit. It used to have 3 little squares which you can drag it around. I changed it into 12 different coloured squares, with the different Neon labels at the front. So you can easily change the background colour by dragging different square behind the neon coloured text.

When the project starts, you will see something as below. You will notice each colour was displayed twice. The reason for that is, the 2 links I mentioned above used slightly different techniques. The Cocoanetics one defined 3 colours (insideColor, outlineColor, blurColor) with different "alpha" value. So I created 2 objects (both extending UILabel) one accepting UIColor, while the other accepts R/G/B value separately so that the code can have different alpha value specified (this is because I can't change alpha value of UIColor?). The top 5 labels uses "NeonLabel" while the bottom 5 uses "NeonLabelRGB" object, have a look carefully and see if you can spot the differences.

In my opinion, although the RGB method indeed creates a slightly better blurring effect, it's too much trouble to have to pass R/G/B value on every call. I still prefer the easier way to make my life easier...

After you dragged a few boxes around, you will get a slightly messier screen as below for you to compare the effect of different coloured neon label on different coloured background.
Hope you find this project interesting!

Source of the Neon Label Test project

Friday, 26 August 2011

Improved ListAllFonts

I was playing around with the "ListAllFonts" project I had before, but noticed a problem: although it's quite handy to have al the font names available, it's not much use unless I can visually see what each font looks like. Changing the font of a label one font name at a time is just too dumb...

Also added 2 new things just learned: block-code and UIScrollView.

A simple block-code to show font and automatically increase the "y" value is as below. It accepts 3 parameters: the view (UIScrollView), the string to be displayed and the font name.

void (^showFonts)(UIView *,NSString *,NSString *) = ^(UIView *uView, NSString *msg,NSString *fName) {
    UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(xx, yy, uView.frame.size.width, fontSize*2)];
    [tmpLabel setText:msg];
    [tmpLabel setFont:[UIFont fontWithName:fName size:fontSize]]; 
    [tmpLabel setTextColor:[UIColor blackColor]];
    [tmpLabel setBackgroundColor:[UIColor clearColor]];
    [tmpLabel setShadowColor:[UIColor yellowColor]];
    [tmpLabel setOpaque:NO];
    [tmpLabel setAlpha:1.0];
    [uView addSubview:tmpLabel];
    [tmpLabel release];

The UIScrollView is also quite simple, I was stuck with the "content size" for a while - I set it to be the same as current screen size in the beginning and was scratching my head wondering how come it wouldn't scroll??  Well, of course it won't, unless I set it to a much bigger size....

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];   
    [scrollView setScrollEnabled:YES];
    [scrollView setContentSize:CGSizeMake(screenWidth,(1000-screenHeight)*25)];
    [self.view addSubview:scrollView];
    [scrollView release];

The result is quite nice, as shown below.

And yes, with the limited display area, how could I forget about the landscape mode? So I also changed it a bit so that it automatically redisplay the content if the device orientation changed:

Note: hasn't got time to run through instruments to check for memory leak or other problems - please let me know if you noticed any.


Source to V2 of ListAllFonts

[Update 05/04/2012] Found this web site which listed out all iOS fonts for iOS5, which you might also find it handy.

[Update 03/05/2012]
I run it with iPhone 4.3 simulator, it listed 42 different fonts.
Then run it with iPhone 5.0/5.1 simulator, both listed 58 different fonts.

Wednesday, 24 August 2011

Don't always need an UILabel to display a NSString

I always thought to display a NSString on a view, you need to create a UILabel. But from Apple's "iOS Development Guide", looks like this might not be the case. The "Hello World" example in Page 23 of the guide shows some code (Listing 1-1) as below to display a NSString directly using "drawAtPoint", which is quite interesting...

- (void)drawRect:(CGRect) rect { 
    NSString *hello = @"Hello, World!"
    CGPoint location = CGPointMake(10, 20); 
    UIFont *font = [UIFont systemFontOfSize:24.0]; 
    [[UIColor whiteColor] set]; 
    [hello drawAtPoint:location withFont:font];

I guess the downside of doing it like this is, you can't reference back to the same NSString later to perform further actions, such as change content, change location, hide the text, ...etc.

Sunday, 21 August 2011

Better way to handle switching between multiple view controllers?

Was looking at this sample code from Apple called "AlternateViews" which demonstrates the switching between 2 View Controllers when the device orientation changes.

I found a few interesting things about the code:

1. The "PortraitViewController" is loaded first, it then loads the "LandscapeViewController" in the viewDidLoad() of "PortraitViewController".

2. There's this new piece of code which I never seen before (as below) using NSNotificationCenter, which sets to call "orientationChanged" method when the orientation changed.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification object:nil];

3. When the orientation changed to Landscape, it calls the following "presentModalViewController" code to switch to the "LandscapeViewController"

[self presentModalViewController:self.landscapeViewController animated:YES];

4. When the orientation changed back to Portrait, it calls the following code to switch back.

[self dismissModalViewControllerAnimated:YES];

This way of switching between multiple view controllers is new to me, plus the way the change of orientation been handled is quite interesting too. Will certainly give it a try on some of my projects.

Friday, 19 August 2011

Minutes to Midnight - rotatable version

The 3rd and 4th project with AppsAmuck wasn't that interesting. So I updated the "Minutes to Midnight" project with rotation capability.

Now the display automatically adjusts it's location when the device rotated. Source code available below.

Code for Rotatable Minutes to Midnight

Thursday, 18 August 2011

Following AppsAmuck's 31 Example Applications

Saw this site called AppsAmuck which provides 31 example applications. Just started yesterday and up to the 2nd one now. It's quite interesting as the site provides detail information plus the source code - although it's a bit out of date.

The 1st example is about showing a clock counting down to midnight. As shown below, the code can't compile in XCode 4, after some research on the net I got it working and added another clock on top - one showing the current time, the other showing the count down. I think this would be quite handy if you need to write some game and have a count down displayed somewhere.

The 2nd one is about animation. As the old code still compiles, I was a bit lazy and just played around with it, added another animation I downloaded somewhere (I forgot :-P ) about street fighter. Quite interesting watching it punching left, right and center above the lively fire background.

Wonder how many days can I go on, I think everyone should have a try!

Wednesday, 17 August 2011

List out all font names

Thanks to Ajnaware’s Weblog I was able to list out all the font names, as shown in the attached screen dump. You should have a try too!

[Update] Please see this new post which shows improved version that also displays each font in scrollable view.

    // List all fonts on iPhone
    NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
    NSArray *fontNames;
    NSInteger indFamily, indFont;
    for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
        NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
        fontNames = [[NSArray alloc] initWithArray:
                     [UIFont fontNamesForFamilyName:
                      [familyNames objectAtIndex:indFamily]]];
        for (indFont=0; indFont<[fontNames count]; ++indFont)
            NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
        [fontNames release];
    [familyNames release];

[Update 05/04/2012] Found this web site which listed out all iOS fonts for iOS5, which you might also find it handy.

Monday, 15 August 2011

Open Source Game: Simple Ball Bouncing Game Ver 2

I expanded the simple ball bouncing game a bit. It now has a few more functions:
-added game pause function
-added left/right direction movement, toggle between up/left-right movement with direction button
-starts with 1 ball, get extra ball every 100 points (max 5 balls)
-added device rotation handling
-added top score recording using application preference

A simple video of the game is below:

Also learned some new skills, this is my first project with proper device rotation handling (using empty NIB design as the NIB-less design still have problem with rotation handling), and also my first project with saving data in application preference.

For example: I was following the instructions from chapter 7 of "Beginning iOS 4 application Development" for device rotation handling. But found that if I use "willAnimateSecondHalfOfRotationFromInterfaceOrientation" I keep getting this strange message shown below and the program will stop after running for a while: "Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations."

Don't know what the hell is "two-stage rotation animation", but after a few searches on the net, I fixed it by replacing the "willAnimateSecondHalfOfRotationFromInterfaceOrientation" function with "willAnimateRotationToInterfaceOrientation".

The source code available here

Thursday, 11 August 2011

Open Source Game: Simple Ball Bouncing Game

Based on YouTube video http://www.youtube.com/watch?v=iGwZoowB-6Y&feature=related by TheEagle1100, I learned quite a lot of new things and created this new simple ball bouncing game: the timer, the game state, the way to move the balls, move the platform down, setup the scores, ...etc.

As shown in screen dump below, there's a few balls bouncing up and down, getting scores on every bounce. When the balls bounced above top 1/4 of the screen, the green platforms moved down and more new ones appeared at the top.

Due to the problem with the NIB-less template I used before - which wouldn't rotate properly, I now use an "empty" NIB, finally it rotates as expected this time.

Instead of 1 single ball and 5 hard coded IBOutlet in the YouTube video, in my project both the platforms and balls are defined using arrays, and you can freely adjust the parameters to get more platforms or/and balls. The NIB was left empty and all UIImageView, UIButton, UILabel objects were added by code.

In the YouTube video (not this one but part 8 or 9? can't remember), TheEagle1100 also demonstrated how to setup the code to control the ball movement in the real device by tilting it around. Unfortunately I only have the simulator, so that part wasn't included.

I also removed the menu and changed the ending part with a button. Hope you find it interesting.

Source to double simple game

When can we have XCode Running on iPhone/iPad?

Was thinking, now that the iPhone/iPad devices are getting more powerful in every generation, wonder how long will it take before Apple release a "portable/mobile" version of XCode that runs on iPhone/iPad? In that case, we can all do development on the same device, how cool is that?

Saturday, 6 August 2011

Can't have array in @property?

Was following this You Tube Video "Making a simple iPhone game, part 2 by TheEagle1100 (DBaird Software), but I tried to do it in slightly different way. Instead of declaring 5 UIImageView calling them "*platform1" to "*platform5", I used an array to save the effort of duplicating.

However when I put in declaration for @property as below, as shown in screen dump above I get 2 errors. 1st about "Property cannot have array or function type 'UIImageView *[5]", the 2nd one says "Property with 'retain' attribute must be of object type.

@property (nonatomic, retain) IBOutlet UIImageView *platform[5];

If I remove the "retain" it will get rid of the 2nd error, but the first error remains....

Based on my "limited" understanding of how "@property" works, it's mainly for the getter and setters, so may be I have to write my own getter/setter or try some other way...

Friday, 5 August 2011

Why my NIB-less projects won't auto-rotate?

Found a problem with the NIB-less projects I have created so far. For some unknown reason, it won't auto-rotate? That is, if I create a simple NIB-less project with only 1 button and 1 label, and then rotate the simulator to either direction, then even if I change the "shouldAutorotateToInterfaceOrientation" as below to always return "YES", it won't move at all?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;

However, if I create another new project with NIB and create same button, label and same change to "shouldAutorotateToInterfaceOrientation" as above, both the button and label rotates nicely, why???

Very strange... Tried using the "nib2objc" tool to analysis the XIB file and it dumps lots of info about the view shown below, but still couldn't work out which property/attribute should be copied over to NIB-less version to make it auto-rotate... I am stuck :-( !!!

UIView *view6 = [[UIView alloc] initWithFrame:CGRectMake(0.0, 20.0, 320.0, 460.0)];
view6.frame = CGRectMake(0.0, 20.0, 320.0, 460.0);
view6.alpha = 1.000;
view6.alphaValue = // unknown property: 1;
view6.autoresizesSubviews = YES;
view6.autoresizesSubviewsForDevice = // unknown property: 1;
view6.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
view6.backgroundColor = [UIColor colorWithWhite:0.750 alpha:1.000];
view6.backgroundFilters = // unknown property: (
view6.canDrawConcurrently = // unknown property: 0;
view6.clearsContextBeforeDrawing = NO;
view6.clipsSubviews = // unknown property: 0;
view6.clipsToBounds = NO;
view6.contentFilters = // unknown property: (
view6.contentMode = UIViewContentModeScaleToFill;
view6.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}");
view6.focusRingType = // unknown property: 0;
view6.frameCenterRotation = // unknown property: 0;
view6.frameOrigin = // unknown property: {0, 20};
view6.frameSize = // unknown property: {320, 460};
view6.hidden = NO;
view6.ibExternalIdentityShowNotesWithSelection = // unknown property: 0;
view6.multipleTouchEnabled = NO;
view6.opaque = YES;
view6.opaqueForDevice = // unknown property: 1;
view6.simulatedOrientationMetrics = // unknown property: [This value is not printable by ibtool (IBUISimulatedOrientationMetrics)];
view6.simulatedStatusBarMetrics = // unknown property: [This value is not printable by ibtool (IBUISimulatedStatusBarMetrics)];
view6.tag = 0;
view6.userInteractionEnabled = YES;
view6.wantsLayer = // unknown property: 0;