IOS UI 第八篇:基本UI
实现图片的滚动,并且自动停止在每张图片上
{
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 200)];
for (int i=1; i<=8; ++i) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(320*(i-1), 0, 320, 200)];
imageView.image = image;
[scrollView addSubview:imageView];
}
scrollView.bounces = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(320*8, 200);
[self.view addSubview:scrollView];
// Do any additional setup after loading the view.
}
{
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 30, 300, 400)];
scrollView.backgroundColor = [UIColor orangeColor];
UIImage *image = [UIImage imageNamed:@"1.jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: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.
}
@property (weak, nonatomic) IBOutlet 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];
//label、imageview默认不接受人机交互,要手动设置
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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。