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

IOS UI 第八篇:基本UI,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。