Created by MBAonline.com
Created by MBAonline.com
Sometimes one requires to have a zoom function in a UITextView. Although zooming is available for UIWebView, this control might not always be the right choice when displaying ASCII text files. We’ve created a simple zoom function that uses the swipe gesture to zoom the content of a UITextView. In order to do so, we need to subclass UITextView, overwrite the methods to handle touches and add an overlay view that is used for user feedback.
In the initialization method, we need to add the overlay view and its subviews that indicate the zoom level:
[sourcecode language="objc"]
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
fontSize = 12;
overlayView = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 320, 28)];
overlayView.backgroundColor = [UIColor clearColor];
overlayView.alpha = 0.6f;
fontSizeBoxOne = [[UIView alloc]initWithFrame:CGRectMake(5, 5, 20, 20)];
fontSizeBoxOne.backgroundColor = [UIColor grayColor];
fontSizeBoxOne.alpha = 0.6f;
fontSizeBoxOne.hidden = YES;
[overlayView addSubview:fontSizeBoxOne];
[fontSizeBoxOne release];
fontSizeBoxTwo = [[UIView alloc]initWithFrame:CGRectMake(30, 5, 20, 20)];
fontSizeBoxTwo.backgroundColor = [UIColor grayColor];
fontSizeBoxTwo.alpha = 0.6f;
fontSizeBoxTwo.hidden = YES;
[overlayView addSubview:fontSizeBoxTwo];
[fontSizeBoxTwo release];
fontSizeBoxThree = [[UIView alloc]initWithFrame:CGRectMake(55, 5, 20, 20)];
fontSizeBoxThree.backgroundColor = [UIColor grayColor];
fontSizeBoxThree.alpha = 0.6f;
fontSizeBoxThree.hidden = YES;
[overlayView addSubview:fontSizeBoxThree];
[fontSizeBoxThree release];
fontSizeBoxFour = [[UIView alloc]initWithFrame:CGRectMake(80, 5, 20, 20)];
fontSizeBoxFour.backgroundColor = [UIColor grayColor];
fontSizeBoxFour.alpha = 0.6f;
fontSizeBoxFour.hidden = YES;
[overlayView addSubview:fontSizeBoxFour];
[fontSizeBoxFour release];
fontSizeBoxFive = [[UIView alloc]initWithFrame:CGRectMake(105, 5, 20, 20)];
fontSizeBoxFive.backgroundColor = [UIColor grayColor];
fontSizeBoxFive.alpha = 0.6f;
fontSizeBoxFive.hidden = YES;
[overlayView addSubview:fontSizeBoxFive];
[fontSizeBoxFive release];
}
return self;
}
[/sourcecode]
When a touch event is detected, we need to store the point where the swipe gesture began:
[sourcecode language="objc"]
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self];
initialDirection = 0;
[self.superview addSubview:overlayView];
}
[/sourcecode]
The variable initialDirection is used to indicate the swipe direction and to register changes in the swipe direction during the swipe gesture. This allows us to use
During the touch, we check for the distance between the starting point and the current position. We either increase the font size by 0.5 points or decrease it by 0.5 points. Simultaneously, we display an overlay view
[sourcecode language="objc"]
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self];
CGFloat deltaX = fabsf(gestureStartPoint.x – currentPosition.x);
if (abs(deltaX)>=initialDirection) {
initialDirection = abs(deltaX);
} else {
gestureStartPoint = [touch locationInView:self];
initialDirection = 0;
}
CGFloat direction = gestureStartPoint.x – currentPosition.x;
CGFloat deltaY = fabsf(gestureStartPoint.y – currentPosition.y);
if (deltaX>=kMinimumGestureLength && deltaY< =kMaximumVariance) {
if (direction<0) {
NSLog(@"font++");
if (fontSize<MAXFONTSIZE) {
fontSize = fontSize + 0.5;
self.font = [UIFont fontWithName:@"Verdana" size:fontSize];
}
} else {
NSLog(@"font–");
if (fontSize>MINFONTSIZE) {
fontSize = fontSize – 0.5;
self.font = [UIFont fontWithName:@"Verdana" size:fontSize];
}
}
if (fontSize>=15) {
fontSizeBoxOne.hidden = NO;
} else {
fontSizeBoxOne.hidden = YES;
}
if (fontSize>=16) {
fontSizeBoxTwo.hidden = NO;
} else {
fontSizeBoxTwo.hidden = YES;
}
if (fontSize>=17) {
fontSizeBoxThree.hidden = NO;
} else {
fontSizeBoxThree.hidden = YES;
}
if (fontSize>=18) {
fontSizeBoxFour.hidden = NO;
} else {
fontSizeBoxFour.hidden = YES;
}
if (fontSize>=19) {
fontSizeBoxFive.hidden = NO;
} else {
fontSizeBoxFive.hidden = YES;
}
}
}
[/sourcecode]
And finally, we need to remove the overlay view:
[sourcecode language="objc"]
(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
initialDirection = 0;
[overlayView removeFromSuperview];
}
[/sourcecode]
The complete project can be downloaded from here
your coding ikangai team
The future of smartphones lies within apps and app stores. This is more or less the new mantra of telcos which were struggling to find the killer app for the smartphone over the last couple of years. They have now realized that there is no killer app for mobile phones per se, but the mobile phone itself – so to speak – is the killer app. It is just a question of using it in the right way – this can be done in a couple of ways and you need apps for it. Consequently, telcos mistakenly kept looking for the killer app that they could offer to their customers.
In the meantime, companies like Apple and Google did precisely what telcos were never able to do: create App Stores and let people download their own killer apps.
Even when it had already become apparent that music downloads were tremendously successful and the iTunes store had turned into a cash-cow for Apple within only a couple of years and even after Apple and Google had opened their app stores, telcos continued to keep their well known business model: let the customer pay for the use of their networks. This can be a bit awkward, if you remember all that fuzz about not being able to use skype on the iphone over a 3g connection, allegedly for technical reasons . One cannot help but wonder what is happening in the minds of telcos: it seems that they are similar to people in the music business: “New Internet technology! Nah! Just let these geeks play a bit… None of our business… we are interested in making money and that’s the real thing.”
Now telcos are a bit scared, because they are starting to realize that they have lost control over the user. The deals with companies like Apple aptly illustrate that the rules are made by different players now. Google, for example, doesn’t even bother to make an exclusive deal with telcos, they just create their own “Google Phone”. And one of the last resorts is also already taken by Apple and Google: mobile advertising.
It seems that telcos are going to have a pretty hard time in the near future and they probably should start doing something – but some of the exits are already blocked and it’s going to be difficult for them in the future. Maybe, one day we will witness that Google simply buys a telco and creates its own internet – the servers are already there, you have the Google phone and the one or the other Google Tablet will certainly emerge in the near future.
your musing ikangai team
The Objective C language bears a few hurdles that new developers need to overcome. When browsing blogs and forums, there are a lot of posts concerned with memory management. A good point to start where to look is obvious Apple’s developer forum, but there are also other pages on the Web, which provide useful information.
A very simple guide that explains the use of NSZombieEnabled can be found here – thanks to the guys from paper bag for that link. Another, broader collection of tips can be found here.
Your ikangai team
After Apple updated the iPhone with the new firmware, it seemed that jailbreaking would be difficult to impossible. However, this is not true any more and the new iPhones can also be jailbroken. The Dev-Team provides insight in the process of jailbreaking the new iPhone firmware version along with a link to the software.
Your ikangai team
I still don’t know what I was waiting for
And my time was running wild
A million dead-end streets
Every time I thought I’d got it made
It seemed the taste was not so sweet
These lines by David Bowie summarize the feelings an iPhone developer has, when dealing with Apple’s APIs. In our case, we had to work with the bluetooth API of Apple which has its issues (connection losses, etc.). We had troubles of all kinds with the bluetooth API and we are now having one the most frustrating developer experiences: the unannounced and invisible bluetooth API change. We used a certain a callback (didFailWithError) to determine if the iPhone had bluetooth activated or not. This worked fine in 3.0 and helped to overcome the bluetooth API limitation of not being able to detect if bluetooth was on/off with your own code. Apple quietly changed this in the new version of the firmware and this is not working any more. On top of that, Apple didn’t provide a subsitute function to detect the bluetooth state in the new version of the firmware.
The result of this? If your App requires bluetooth and you do not tell the user to turn on bluetooth (which is quite difficult if you cannot detect the bluetooth state programmatically), your App won’t work and Apple can reject your App, arguing that the user may be confused.
Your ikangai team