小小词典(五,弹出视图和手势)

我们来为应用添加一个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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值