1. scrollView缩小放大:
设置代理scrollVIew.delegate=self;
代理类遵循<UIScrollViewDelegate>协议;
重写方法 -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return_imageView;
}
2. scrollView分页:
CGFloat w = scrollView.frame.size.width;
//添加图片
for (int i=0; i<pCount;i++) {
NSString *imageName = [NSStringstringWithFormat:@"scrollview_0%d.png",i];
UIImage *image = [UIImageimageNamed:imageName];
_imageView = [[UIImageViewalloc]initWithImage:image];
_imageView.frame = CGRectMake(i * w,0, [UIScreenmainScreen].bounds.size.width,120);
[scrollViewaddSubview:_imageView];
}
scrollView.contentSize =CGSizeMake(_imageView.bounds.size.width *pCount,0);
//允许分页,分页宽度为scrollView的contentSize.size.x
scrollView.pagingEnabled =YES;
//添加分页的下标,一个个小圆点
UIPageControl *pageControl = [[UIPageControlalloc]init];
pageControl.center =CGPointMake(w *0.5,253);
//pageControl.bounds = CGRectMake(0, 0, 150, 50);
pageControl.numberOfPages =pCount;
_pageControl = pageControl;
[self.viewaddSubview:pageControl];
实现代理方法,让scrollView滚动的时候,实时更新下表小圆点
-(void) scrollViewDidScroll:(UIScrollView *)scrollView{
int page =_scrollView.contentOffset.x/_scrollView.frame.size.width;
_pageControl.currentPage = page;
}
3. 固定横屏方案一:
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
4. 固定横屏方案二:
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
//CartoonPlayerViewController dismiss的时候还是进if,即presentedViewController还是CartoonPlayerViewController,所以这样写
if ([self.window.rootViewController.presentedViewController isKindOfClass: [CartoonPlayerViewController class]])
{
CartoonPlayerViewController* vc=(CartoonPlayerViewController*)self.window.rootViewController.presentedViewController;
if (vc.isPresented) { //isPresent 是自己在</span><span style="font-size: 14px; font-family: Menlo;">CartoonPlayerViewController中定义的属性,dismiss时候设为NO即可</span><span style="font-size:14px;">
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
CGFloat version=[[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 8.0 && version < 9.0) {
return UIInterfaceOrientationMaskLandscapeRight;
}
else return UIInterfaceOrientationMaskLandscape;
}
else{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
return UIInterfaceOrientationMaskLandscape;
}
}
else{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
return UIInterfaceOrientationMaskLandscape;
}
}
5. 找到沙盒中的document文件夹下的第一个视频文件:
- -(NSString*)findVideoInDocuments
- {
- NSString *documentsPath = [NSString stringWithFormat:@"%@/Documents", NSHomeDirectory()];
- NSFileManager *fileMg = [[NSFileManager alloc] init];
- //遍历Documents下的文件,找到视频文件就返回它的全路径
- NSArray *subPaths = [fileMg contentsOfDirectoryAtPath:documentsPath error:nil];
- if (subPaths) {
- for (NSString *subPath in subPaths) {
- if ( [self isMediaFile:[subPath pathExtension]]) {
- NSString *path = [documentsPath stringByAppendingPathComponent:subPath];
- return path;
- }
- }
- }
- return nil;
- }
- -(BOOL)isMediaFile:(NSString*)pathExtension
- {
- //可用格式
- /*
- ".M1V", ".MP2", ".MPE", ".MPG", ".WMAA",
- ".MPEG", ".MP4", ".M4V", ".3GP", ".3GPP", ".3G2", ".3GPP2", ".MKV",
- ".WEBM", ".MTS", ".TS", ".TP", ".WMV", ".ASF", ".ASX", ".FLV",
- ".MOV", ".QT", ".RM", ".RMVB", ".VOB", ".DAT", ".AVI", ".OGV",
- ".OGG", ".VIV", ".VIVO", ".WTV", ".AVS", ".SWF", ".YUV"
- */
- //简单粗暴地判断是否为视频格式,这里先试6个
- NSString*ext = [pathExtension uppercaseString];
- if([ext isEqualToString:@"MP4"])
- {
- return YES;
- }
- else if([ext isEqualToString:@"MOV"])
- {
- return YES;
- }
- else if([ext isEqualToString:@"RMVB"])
- {
- return YES;
- }
- else if([ext isEqualToString:@"MKV"])
- {
- return YES;
- }
- else if([ext isEqualToString:@"FLV"])
- {
- return YES;
- }
- else if([ext isEqualToString:@"TS"])
- {
- return YES;
- }
- return NO;
- }
-(instancetype)init{
self = [super init];
if (self) {
[[UINavigationBar appearance] setBackgroundImage:[BabybusTool imageWithColor:[UIColor redColor]] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
}
return self;
}