我们来为应用添加一个about窗口。在Xcode中选择New File,选择Objective-c class,选择父类为UIViewController,名字为AboutViewController,并选择xib文件。为新窗口添加一个ImageView,增加图片。然后添加text view输入相关的版权消息。
在viewController.xib中Navigation bar右上角,增加一个bar button item,修改名字为关于。并关联方法:pressAbout
在viewController.m中加入#import"AboutViewController.h"
修改pressAbout
- (IBAction)pressAbout:(id)sender {
AboutViewController *about=[[[AboutViewControlleralloc]initWithNibName:@"AboutViewController"bundle:nil]autorelease];
about.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;//弹出窗口的方式
[selfpresentModalViewController:aboutanimated:YES];//弹出窗口
}
为了能从关于窗口回到主窗口,我们添加手势。手势
UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UISwipeGestureRecognizer
UIPanGestureRecognizer
UILongPressGestureRecognizer
为AboutViewController添加UISwipeGestureRecognizer。
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view from its nib.
UISwipeGestureRecognizer *swipe=[[[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(handleSwipe:)]autorelease];
swipe.direction=UISwipeGestureRecognizerDirectionDown;
[self.viewaddGestureRecognizer:swipe];
}
- (void)handleSwipe:(UISwipeGestureRecognizer*)g
{
[selfdismissModalViewControllerAnimated:YES];
}
再给AboutViewController添加一个UIPinchGestureRecognizer用来放大或缩小关于中的文字。
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view from its nib.
UISwipeGestureRecognizer *swipe=[[[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(handleSwipe:)]autorelease];
swipe.direction=UISwipeGestureRecognizerDirectionDown;
[self.viewaddGestureRecognizer:swipe];
UIPinchGestureRecognizer *pinch=[[[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(handlePinch:)]autorelease];
[self.viewaddGestureRecognizer:pinch];
}
- (void) handlePinch:(UIPinchGestureRecognizer*)g
{
if (g.scale>1.0) {
_textView.font=[UIFontsystemFontOfSize:_textView.font.pointSize+1];
}else {
if (_textView.font.pointSize>8) {
_textView.font=[UIFontsystemFontOfSize:_textView.font.pointSize-1];
}
}
}
源码地址:http://download.csdn.net/detail/cloud95/5185703