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];
}
2010-06-15 09:35:14.408 JoyPlayer[494:207] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:772
2010-06-15 09:35:14.408 JoyPlayer[494:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'
2010-06-15 09:35:14.409 JoyPlayer[494:207] Stack: (
36209755,
2528503049,
36293691,
2776852,
5075846,
5020217,
43132,
387640,
2454948,
2454803,
32134584,
32132632,
32135830,
31795157,
35993825,
35990600,
41654157,
41654354,
4763651,
10756,
10610
)
- (IBAction)sendSMS {
BOOL canSendSMS = [MFMessageComposeViewController canSendText];
NSLog(@"can send SMS [%d]", canSendSMS);
if (canSendSMS) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.navigationBar.tintColor = [UIColor blackColor];
picker.body = @"test";
picker.recipients = [NSArray arrayWithObject:@"186-0123-0123"];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
// Notifies users about errors associated with the interface
switch (result) {
case MessageComposeResultCancelled:
if (DEBUG) NSLog(@"Result: canceled");
break;
case MessageComposeResultSent:
if (DEBUG) NSLog(@"Result: Sent");
break;
case MessageComposeResultFailed:
if (DEBUG) NSLog(@"Result: Failed");
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
LOGO_320×44.png 图片显示在背景上,
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
//加入旋转坐标系代码
// Drawing code
UIImage *navBarImage = [UIImage imageNamed:@"LOGO_320×44.png"];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, self.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGPoint center=self.center;
CGImageRef cgImage= CGImageCreateWithImageInRect(navBarImage.CGImage, CGRectMake(0, 0, 1, 44));
CGContextDrawImage(context, CGRectMake(center.x-160-80, 0, 80, self.frame.size.height), cgImage);
CGContextDrawImage(context, CGRectMake(center.x-160, 0, 320, self.frame.size.height), navBarImage.CGImage);
CGContextDrawImage(context, CGRectMake(center.x+160, 0, 80, self.frame.size.height), cgImage);
}
@end
old code
CGContextDrawImage(context, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), navBarImage.CGImage);
- (void)configureView:(NSString *)performaction {
if ([performaction length] >0) {
SEL sel=sel_registerName([performaction UTF8String]);
if ([self respondsToSelector:sel]) {
[self performSelector:sel];
}
}
}
本文简要介绍如何使用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];
}
//
// Greeting.h 头文件
// cpp_demo
//
// Created by 孔祥波 on 10-5-24.
// Copyright 2010 aaa. All rights reserved.
//
#import <Foundation/Foundation.h>
class Hello {
private:
id greeting_text; // holds an NSString
public:
Hello() {
greeting_text = @"Hello, world!";
}
Hello(const char* initial_greeting_text) {
greeting_text = [[NSString alloc] initWithUTF8String:initial_greeting_text];
}
void say_hello() {
printf("%s\n", [greeting_text UTF8String]);
}
};
@interface Greeting : NSObject {
@private
Hello *hello;
}
- (id)init;
- (void)dealloc;
- (void)sayGreeting;
- (void)sayGreeting:(Hello*)greeting;
@end
RegexKitLite 之前搞过,但是内弄清楚,这次必须搞好。
下面是测试代码,在SDK 4.0 上通过。3.2一下NSRegularExpressionSearch 不支持,自己想办法吧。
-(void)test
{
NSString *html=[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1.html" ofType:nil] encoding:NSUTF8StringEncoding error:nil];
//NSString *exp=@"/(https?)://(\\d+))?((?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\]*)+)?/";
NSString *exp=@"http://[^ ]*.(png|jpeg|PNG|JPEG|JPG|jpg)";
NSRange r;
for(NSString *match in [html componentsMatchedByRegex:exp]) {
NSLog(@"111Phone number is %@", match);
}
r = [html rangeOfString:exp options:NSRegularExpressionSearch];
if (r.location != NSNotFound) {
NSLog(@"Phone number is %@", [html substringWithRange:r]);
} else {
NSLog(@"Not found.");
}
}
result = MakeServerConnection("gateway.sandbox.push.apple.com", 2195, &socket, &peer);
result = SSLSetPeerDomainName(context, "gateway.push.apple.com", 30);
if( homeViewObj != nil )
{
channelViewObj = [[CChannelsView alloc] init];
if( channelViewObj != nil )
{
searchViewObj = [[CSearchView alloc] init];
if( searchViewObj != nil )
{
downloadViewObj = [[CDownloadView alloc] init];
if( downloadViewObj != nil )
{
topicNaviObj = [[CTopicNavi alloc] init];
if ( topicNaviObj != nil )
{
rankingNaviObj = [[CRankingNaviView alloc] init];
if ( rankingNaviObj != nil )
{
collectionNaviObj = [[CollectionNavi alloc] init];
if ( collectionNaviObj != nil )
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
// NSLog(@"good to see it");
if (self.selectedViewController == viewController ) {
if ([((UINavigationController*)viewController).visibleViewController respondsToSelector:@selector(showCategoryBtns)]) {
[ (TableViewController*)(((UINavigationController*)viewController).visibleViewController) showCategoryBtns];
return NO;解决问题关键
}
}
return YES;
}


Recent Comments