Recently in iPhone Category
UIViewAnimationWithBlocks使用block,动画结束后不需要使用回调方法,相比UIViewAnimation 方式要简洁很多
- (void)setSelectedVeg:(id)sender
{
[selectedVegetableIcon setAlpha:0.0];
[UIView animateWithDuration:0.4
animations: ^{
float angle = [self spinnerAngleForVegetable:sender];
[vegetableSpinner setTransform:CGAffineTransformMakeRotation(angle)];
}
completion:^(BOOL finished) {
[selectedVegetableIcon setAlpha:1.0];
}];
}
以上代码来自WWDC2010 iPlant PlantCareViem.m
UIViewAnimation style Animation
- (void)setSelectedVeg:(id)sender
{
[selectedVegetableIcon setAlpha:0.0];
[UIView beginAnimations:@"setSelectedVeg" context:nil];
float angle = [self spinnerAngleForVegetable:sender];
[vegetableSpinner setTransform:CGAffineTransformMakeRotation(angle)];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(done)];
[UIView commitAnimations];
}
-(void)done
{
[selectedVegetableIcon setAlpha:1.0];
}
本文简要介绍如何使用KVO 跟踪NSOperation 状态
traceOperation 方法跟踪 PageLoadOperation(NSOperation 子类)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
for (NSString *urlString in urlArray)
{
NSURL *url = [NSURL URLWithString:urlString];
PageLoadOperation *plo = [[PageLoadOperation alloc] initWithURL:url];
[queue addOperation:plo];
[self traceOperation:plo];
[plo release];
}
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
traceOperation 方法
KVO-Compliant Properties
The NSOperation class is key-value coding (KVC) and key-value observing (KVO) compliant for several of its properties. As needed, you can observe these properties to control other parts of your application. The properties you can observe include the following:
isCancelled- read-only propertyisConcurrent- read-only propertyisExecuting- read-only propertyisFinished- read-only propertyisReady- read-only propertydependencies- read-only propertyqueuePriority- readable and writable propertycompletionBlock- readable and writable property (Mac OS X only)
-(void)traceOperation:(NSOperation*)obj
{
[obj addObserver:self
forKeyPath:@"isExecuting"
options:0
context:NULL];
[obj addObserver:self
forKeyPath:@"isFinished"
options:0
context:NULL];
[obj addObserver:self
forKeyPath:@"isReady"
options:0
context:NULL];
[obj addObserver:self
forKeyPath:@"isCancelled"
options:0
context:NULL];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ApplicationCell";
ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
#if USE_INDIVIDUAL_SUBVIEWS_CELL
[[NSBundle mainBundle] loadNibNamed:@"IndividualSubviewsBasedApplicationCell" owner:self options:nil];
cell = tmpCell;
self.tmpCell = nil;
#elif USE_COMPOSITE_SUBVIEW_CELL
cell = [[[CompositeSubviewBasedApplicationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ApplicationCell"] autorelease];
#elif USE_HYBRID_CELL
cell = [[[HybridSubviewBasedApplicationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ApplicationCell"] autorelease];
#endif
}
// Display dark and light background in alternate rows -- see tableView:willDisplayCell:forRowAtIndexPath:.
cell.useDarkBackground = (indexPath.row % 2 == 0);
// Configure the data for the cell.
NSDictionary *dataItem = [data objectAtIndex:indexPath.row];
cell.icon = [UIImage imageNamed:[dataItem objectForKey:@"Icon"]];
cell.publisher = [dataItem objectForKey:@"Publisher"];
cell.name = [dataItem objectForKey:@"Name"];
cell.numRatings = [[dataItem objectForKey:@"NumRatings"] intValue];
cell.rating = [[dataItem objectForKey:@"Rating"] floatValue];
cell.price = [dataItem objectForKey:@"Price"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
CGRect backRect = CGRectMake(10, 10, 50, 8);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, backRect);
CGContextTranslateCTM(context, 0.0, self.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextShowTextAtPoint 不能draw中文,中文等UTF8 需要用
地址:上海 长宁 万航渡路2453号 周家桥创意园B区
内容: iPhone 应用&游戏开发
联系人:孔祥波 yarshure@gmail.com

