IOS UI 第八篇:基本UI


实现图片的滚动,并且自动停止在每张图片上
 
 
- (void)viewDidLoad
{
    [
super viewDidLoad];

    
UIScrollView *scrollView = [[UIScrollView allocinitWithFrame:CGRectMake(020320200)];
    
    
for (int i=1; i<=8; ++i) {
        
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
        
UIImageView *imageView = [[UIImageView allocinitWithFrame:CGRectMake(320*(i-1), 0320200)];
        imageView.
image = image;
        [scrollView 
addSubview:imageView];
    }
    
    scrollView.
bounces = NO;
    scrollView.
showsHorizontalScrollIndicator = NO;
    scrollView.
pagingEnabled = YES;
    scrollView.
contentSize = CGSizeMake(320*8200);
    [
self.view addSubview:scrollView];
    
    
    
// Do any additional setup after loading the view.
}
 
 
将图片猩猩假如scrollView 中
 
- (void)viewDidLoad
{
    [
super viewDidLoad];
     
UIScrollView *scrollView = [[UIScrollView allocinitWithFrame:CGRectMake(1030300400)];
     scrollView.
backgroundColor = [UIColor orangeColor];
     
     
UIImage *image = [UIImage imageNamed:@"1.jpg"];
     
UIImageView *imageView = [[UIImageView allocinitWithImage:image];
     [scrollView 
addSubview:imageView];
     scrollView.
contentSize = CGSizeMake(image.size.width, image.size.height);
     [
self.view addSubview:scrollView];
    
    
// Do any additional setup after loading the view.
}
 
手势:
 
@interface QFViewController ()<UIGestureRecognizerDelegate]]>
@property (weaknonatomicIBOutlet UILabel *myLabel;

@end

@implementation QFViewController{
    
CGFloat preScale;
}

- (
void)viewDidLoad
{
    [
super viewDidLoad];
// 手势
    
/*
    UITapGestureRecognizer;//
单击
    UIPinchGestureRecognizer;//
缩放手势
    UIRotationGestureRecognizer;//
旋转手势
    UISwipeGestureRecognizer;//
扫动手势(上下左右)
    UIPanGestureRecognizer;//
滑动手势
     */

    
UIPinchGestureRecognizer *pinchGR=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(onPinch:)];
    [
self.myLabel addGestureRecognizer:pinchGR];
    
//labelimageview默认不接受人机交互,要手动设置
    
self.myLabel.userInteractionEnabled=YES;
    
preScale=1;
}
-(
void)onPinch:(UIPinchGestureRecognizer *)pGR{
    
NSLog(@"%@",pGR);
    
NSLog(@"%f",pGR.scale);
    
/*
     UIGestureRecognizerStateBegan,
     UIGestureRecognizerStateChanged,
     UIGestureRecognizerStateEnded,
     */

    
if (pGR.state==UIGestureRecognizerStateChanged) {
        
self.myLabel.font=[UIFont systemFontOfSize:17*preScale*pGR.scale];
    }
    
if (pGR.state==UIGestureRecognizerStateEnded) {
        
preScale=preScale*pGR.scale;
    }
    
    
}

@end
 

IOS UI 第八篇:基本UI

posted @ 2014-04-13 13:20  Levi.duan  阅读(155)  评论(0编辑  收藏  举报