第七課的主要內容:View Controller Lifecycle ImageView ScrollView WebView
1、View Controller Lifecycle
{
[super viewWillDisappear:animated]; // 這個要寫
 [self rememberScrollPosition]; // 記住滾動的位置
[self saveDataToPermanentStore]; // maybe do in did instead?
// 注意不要在這裏進行比耗時的操作,界面更流暢。
- (void)viewDidDisappear:(BOOL)animated;
- - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)anOrientation
- duration:(NSTimeInterval)seconds;
- - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOriention)orient
- duration:(NSTimeInterval)seconds;
- - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)anOrientation;
- @property UIInterfaceOrientation interfaceOrientati
- - (void)viewDidUnload
- {
- self.faceView = nil;
- }
view controller的初始化:
2、UIImageView
3、UIWebView
- - (void)loadRequest:(NSURLRequest *)request;
- - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL;
- - (void)loadData:(NSData *)data
- MIMEType:(NSString *)MIMEtype
- textEncodingName:(NSString *)encodingName
- baseURL:(NSURL *)baseURL;
- NSURLRequest
- + (NSURLRequest *)requestWithURL:(NSURL *)url;
- + (NSURLRequest *)requestWithURL:(NSURL *)url
- cachePolicy:(NSURLRequestCachePolicy)policy
- timeoutInterval:(NSTimeInterval)timeoutInterval;
4、ScrollView
- UIImage *image = [UIImage imageNamed:@"bigimage"];
- UIImageView *iv = [[UIImageView alloc] initWithImage:image];
- iv.frame = CGRectMake(0, 0, image.size.width, image.size.height) ;
- CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
- UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
- [scrollView addSubview:iv];
- scrollView.contentSize=CGSizeMake(2592 ,1952);
- [self.view addSubview:scrollView];
- -(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
- CGPoint upperLeftOfVisible = scrollView.contentOffset;
- NSLog(@"x:%f, y:%f", upperLeftOfVisible.x, upperLeftOfVisible.y);
- }
- CGRect visibleRect = [scrollView convertRect:scrollView.bounds toView:subview];
UIScrollViewDelegate協議,
- UIImage *image = [UIImage imageNamed:@"bigimage"];
- imageView = [[UIImageView alloc] initWithImage:image];
- imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height) ;
- CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
- UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
- scrollView.delegate = self;
- scrollView.minimumZoomScale = 0.2;
- scrollView.maximumZoomScale = 2.0;
- [scrollView addSubview:imageView];
- scrollView.contentSize=CGSizeMake(2592 ,1952);
- [self.view addSubview:scrollView];
- - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
- {
- return imageView;
- }
容芳志 (http://blog.csdn.net/totogo2010)
本文遵循“署名-非商業用途-保持一致”創作公用協議
原文地址:http://blog.csdn.net/totogo2010/article/details/8471739