iOS开发

面试题一(自定义UIScrollView)

2017-09-22  本文已影响8人  追逐_chase

assign和weak的区别

weak

assgin

bounds和frame的区别

共同点是描述一块区域的

bounds

frame

利用bounds属性自己写一个UIScrolloView

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>

/**自定义ScrolloView*/
@property (nonatomic, weak) UIView *coustonScrolloView;

@end

//1.定义一个customScrolloView
   UIView * customScrolloView = [[UIView alloc] initWithFrame:self.view.bounds];
  coustonScrolloView.backgroundColor = [UIColor redColor];
   self.coustonScrolloView = coustonScrolloView;
   [self.view addSubview: customScrolloView];
//2.添加一个平移手势

 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self  action:@selector(pan:)];
    [coustonScrolloView addGestureRecognizer:pan];
 //3.在自定义的  customScrolloView上添加一个 子控件
    UISwitch *switchF = [[UISwitch alloc] init];
    
    [customScrolloView addSubview:switchF];


//实现平移方法
- (void)pan:(UIPanGestureRecognizer *)pan {
    
    
    CGPoint tarnP = [pan translationInView:pan.view];
    
    CGRect bounce = self.coustonScrolloView.bounds;
    bounce.origin.y -= tarnP.y;
    self.coustonScrolloView.bounds = bounce;
    
    NSLog(@"%@",NSStringFromCGRect(self.coustonScrolloView.bounds));

    //复位  始终保持在上一次平移的基础上的操作
    [pan setTranslation:CGPointZero inView:pan.view];
    
}

效果图:

自定义ScrolloView.gif
上一篇 下一篇

猜你喜欢

热点阅读