zoukankan      html  css  js  c++  java
  • 控件悬停

    #import "ViewController.h"
    
    @interface ViewController () <UIScrollViewDelegate>
    /** 价格view */
    @property (nonatomic, weak) UIView *priceView;
    @property (weak, nonatomic) IBOutlet UISwitch *s;
    @end
    
    @implementation ViewController
    
    static CGFloat const XMGImageH = 100;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        // 滚动
        UIScrollView *scrollView = [[UIScrollView alloc] init];
        scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, 400);
        scrollView.backgroundColor = [UIColor redColor];
        scrollView.contentSize = CGSizeMake(0, 600);
        scrollView.delegate = self;
        [self.view addSubview:scrollView];
        
        // 图片
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.frame = CGRectMake(0, 0, self.view.frame.size.width, XMGImageH);
        imageView.backgroundColor = [UIColor greenColor];
        [scrollView addSubview:imageView];
        
        // 需要悬停的控件
        UIView *priceView = [[UIView alloc] init];
        priceView.frame = CGRectMake(0, XMGImageH, self.view.frame.size.width, 40);
        priceView.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.5];
        [scrollView addSubview:priceView];
        self.priceView = priceView;
        
        UIView *otherView = [[UIView alloc] init];
        otherView.frame = CGRectMake(0, 140, self.view.frame.size.width, 40);
        otherView.backgroundColor = [UIColor yellowColor];
        //[scrollView addSubview:otherView];
    }
    
    #pragma mark - <UIScrollViewDelegate>
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if (scrollView.contentOffset.y >= XMGImageH) {
            CGRect priceF = self.priceView.frame;
            priceF.origin = CGPointZero;
            self.priceView.frame = priceF;
            
            [self.view addSubview:self.priceView];
            
            // 往上移动多少距离, 开关就完全透明
            CGFloat maxDelta = 20;
            
            // 往上移动的距离
            CGFloat delta = scrollView.contentOffset.y - XMGImageH;
            
            // 减小alpha
            self.s.alpha =  1 - delta / maxDelta;
        } else {
            CGRect priceF = self.priceView.frame;
            priceF.origin.y = XMGImageH;
            self.priceView.frame = priceF;
            
            [scrollView addSubview:self.priceView];
        }
    }
    @end
  • 相关阅读:
    Eclipse 快捷键大全
    js字符串变量赋值的时候,一行写不下,想在下一行继续写
    java.lang.ClassNotFoundException: com.opensymphony.xwork2.util.TextUtils
    JS调用iframe父窗口元素和子窗口元素的方法
    no JMagick in java.library.path
    数据库建立索引的原则
    Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    软件项目管理心得
    Errors running builder JavaScript Validator的问题
    21. Session Management
  • 原文地址:https://www.cnblogs.com/developer-ios/p/4934762.html
Copyright © 2011-2022 走看看