内置视图-滚动视图

interface AppDelegate : UIResponder <UIApplicationDelegate, UIScrollViewDelegate>

@property (nonatomic, retain) UIWindow* window;

@property (nonatomic, retain) UIImageView* mapImageView;

@end

#import "AppDelegate.h"

 

@implementationAppDelegate

@synthesize window = _window;

@synthesize mapImageView = _mapImageView;

 

- (void)dealloc

{

    self.mapImageView = nil;

    [_window release];

    [super dealloc];

}

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

{

    _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    //创建图片视图,显示整张北京地图

    _mapImageView = [[UIImageView alloc] initWithImage:

                     [UIImage imageNamed:@"BeijingMap.png"]];

    

    //创建一个滚动视图

    UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:

                                [UIScreen mainScreen].applicationFrame];

    //设置滚动视图要显示的整个地图的尺寸

    scrollView.contentSize = self.mapImageView.frame.size;

    //滚动视图的初始查看位置为地图的正中央

    scrollView.contentOffset = CGPointMake(

                                           (self.mapImageView.frame.size.width - scrollView.frame.size.width)/2,

                                           (self.mapImageView.frame.size.height - scrollView.frame.size.height)/2);

    //计算横纵方向上的缩放比例

    float ratioX = scrollView.frame.size.width/self.mapImageView.frame.size.width;

    float ratioY = scrollView.frame.size.height/self.mapImageView.frame.size.height;

    //设置滚动视图的最小与最大缩放比例

    scrollView.minimumZoomScale = ratioX > ratioY?ratioX: ratioY;

    scrollView.maximumZoomScale = 2;

    //设置滚动视图的委托对象

    scrollView.delegate = self;

   

    [scrollView addSubview:self.mapImageView];

    [self.window addSubview:scrollView];

    [scrollView release];

    

    [self.window makeKeyAndVisible];

    return YES;

}

 

//返回待缩放的视图

- (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView

{

    return self.mapImageView;

}

@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值