iOS技术点杂记--有一天我也会成为大牛

1.  scrollView缩小放大:
 设置代理scrollVIew.delegate=self;
 代理类遵循<UIScrollViewDelegate>协议;
 设置最大最小zoom倍数  scrollView. maximumZoomScale = 2 ;   scrollView. minimumZoomScale = 0.5 ;
 重写方法 -(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.frameCGRectMake(i * w,0, [UIScreenmainScreen].bounds.size.width,120);

        [scrollViewaddSubview:_imageView];

        

    }

    scrollView.contentSize =CGSizeMake(_imageView.bounds.size.width *pCount,0);

    //允许分页,分页宽度为scrollViewcontentSize.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.  固定横屏方案一:
只需在controllerView 中重写以下方法, 需要的类都要写比较麻烦,复制粘帖即可:

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}
                                                                              
4.  固定横屏方案二:
在appDelegate 中,重写一下方法:


-(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文件夹下的第一个视频文件:
  1. -(NSString*)findVideoInDocuments  
  2. {  
  3.     NSString *documentsPath = [NSString stringWithFormat:@"%@/Documents", NSHomeDirectory()];  
  4.     NSFileManager *fileMg = [[NSFileManager alloc] init];  
  5.   
  6.     //遍历Documents下的文件,找到视频文件就返回它的全路径  
  7.     NSArray *subPaths = [fileMg contentsOfDirectoryAtPath:documentsPath error:nil];  
  8.     if (subPaths) {  
  9.         for (NSString *subPath in subPaths) {  
  10.             if ( [self isMediaFile:[subPath pathExtension]]) {  
  11.                 NSString *path = [documentsPath stringByAppendingPathComponent:subPath];  
  12.                 return path;  
  13.             }  
  14.         }  
  15.     }  
  16.     return nil;  
  17. }  

  1. -(BOOL)isMediaFile:(NSString*)pathExtension  
  2. {  
  3.     //可用格式  
  4.     /* 
  5.      ".M1V", ".MP2", ".MPE", ".MPG", ".WMAA", 
  6.      ".MPEG", ".MP4", ".M4V", ".3GP", ".3GPP", ".3G2", ".3GPP2", ".MKV", 
  7.      ".WEBM", ".MTS", ".TS", ".TP", ".WMV", ".ASF", ".ASX", ".FLV", 
  8.      ".MOV", ".QT", ".RM", ".RMVB", ".VOB", ".DAT", ".AVI", ".OGV", 
  9.      ".OGG", ".VIV", ".VIVO", ".WTV", ".AVS", ".SWF", ".YUV" 
  10.      */  
  11.       
  12.     //简单粗暴地判断是否为视频格式,这里先试6个  
  13.     NSString*ext = [pathExtension uppercaseString];  
  14.     if([ext isEqualToString:@"MP4"])  
  15.     {  
  16.         return YES;  
  17.     }  
  18.     else if([ext isEqualToString:@"MOV"])  
  19.     {  
  20.         return YES;  
  21.     }  
  22.     else if([ext isEqualToString:@"RMVB"])  
  23.     {  
  24.         return YES;  
  25.     }  
  26.     else if([ext isEqualToString:@"MKV"])  
  27.     {  
  28.         return YES;  
  29.     }  
  30.     else if([ext isEqualToString:@"FLV"])  
  31.     {  
  32.         return YES;  
  33.     }  
  34.     else if([ext isEqualToString:@"TS"])  
  35.     {  
  36.         return YES;  
  37.     }  
  38.   
  39.     return NO;  
  40. }  
                                                                              
6.  全局引用 pch
   
 项目->New File -> iOS->other->PCH file,然后在info中搜索 Prefix Header 属性(一般在 Apple LLVMx.0 -Language 分类下 ) ,为Prefix Header 属性添加----- $(SRCROOT)/你项目的名字/你创建PCH文件的名字.pch
 
                                                                              
7.改变 UINavigationBar 的背景颜色

要在init初始化的时候设置 在viewDidLoad方法中无效
-(instancetype)init{
    self = [super init];
    if (self) {
        [[UINavigationBar appearance] setBackgroundImage:[BabybusTool imageWithColor:[UIColor redColor]] forBarMetrics:UIBarMetricsDefault];
        [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    }
    return self;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值