屏幕旋转走得方法
//刚要旋转时,执行这个方法。。看看有什么要执行的。
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.myView.lt1.textField resignFirstResponder];
}
结束旋转时走得方法
//已经旋转结束,到这里看看。还有什么指示。
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self.myView.lt1.textField becomeFirstResponder];
}
//设置屏幕可以旋转的方向
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
scrollView的常用属性
UIImage *img = [UIImage imageNamed:@"h.png"];
self.view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"h.png"]] autorelease];
//self.view.frame = CGRectMake(0, 0, 320, 480);
self.uiscrollView = [[[UIScrollView alloc] init]autorelease];
self.uiscrollView.frame = [UIScreen mainScreen].bounds;
//内容尺寸
self.uiscrollView.contentSize = img.size;
//是否有弹动效果
self.uiscrollView.bounces = YES;
//显示内容坐标。出来在某个位置
self.uiscrollView.contentOffset = CGPointMake(1000, 300);
//点击状态栏置顶
self.uiscrollView.scrollsToTop = YES;
//能否滚动。默认是yes;
//self.uiscrollView.scrollEnabled = NO;
//是否显示那个边框。这个是横着的 滚动条
self.uiscrollView.showsHorizontalScrollIndicator = YES;
//这个是竖着的。。就是那个滚动条
self.uiscrollView.showsVerticalScrollIndicator = YES;
//如果内容小于bounds也可以有弹动效果
self.uiscrollView.alwaysBounceHorizontal = YES;
self.uiscrollView.alwaysBounceVertical = YES;
//缩放
self.uiscrollView.minimumZoomScale = 0.2;//缩小到原来的一半
self.uiscrollView.maximumZoomScale = 2;//放大的原来的俩倍
self.uiscrollView.zoomScale = 1;
//缩放的时候是否有弹动效果。
self.uiscrollView.bouncesZoom = YES;
//会多出来边框
self.uiscrollView.contentInset = UIEdgeInsetsMake(100, 100, 100, 100);
[self addSubview:self.uiscrollView];
[self.uiscrollView addSubview:self.view];
用这些方法时一定记得设置代理
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollVie
{
//返回要缩放的视图
return self.root.view;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//只要视图偏移发生变化就过来看看。。有什么大事发生
NSLog(@"发生了什么事");
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
//在视图缩放的时候触发这个方法
NSLog(@"大了,小了");
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
//将要拖拽
NSLog(@"what's happen???");
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
//只要拖拽结束时 进来看看。
NSLog(@"结束了吗???");
}
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
//拖拽完成减速时 进来看看。
NSLog(@"慢点.....");
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//减速结束后视图停稳了 触发改方法
NSLog(@"怎么停了。。。。");
}
UIPageControl 的定义
self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(50, 100, 200, 50)];
self.page.backgroundColor = [UIColor redColor];
self.page.numberOfPages = 5;
[self addSubview:self.page];
pageControl 常用的方法
[self.root.page addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventTouchUpInside];
-(void)pageAction:(UIPageControl *)sender
{
NSLog(@"第%d页",sender.currentPage);
[UIView animateWithDuration:0.1 animations:^{
self.root.scroll.contentOffset = CGPointMake(sender.currentPage *[UIScreen mainScreen].bounds.size.width, 0);
}];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
self.root.page.currentPage = scrollView.contentOffset.x/320;
NSLog(@"终于停了。。");
}