Swift UIView自定义位置

时间:2016-04-07 01:15:44

标签: ios swift

提前抱歉为noob问题:

我有下面的功能,可以完美地使用一个捕捉,这个视图覆盖了我在屏幕底部的按钮。如何调整此功能只是为了在按钮的屏幕底部留出50 px的空间。是否可以使用mainScreen()。bounds并在顶部或底部留下一些空间?

SELECT
wp_grank.ID ,
wp_grank.competitor_ID ,
wp_grank.tournament_ID ,
wp_grank.academy_ID ,
wp_grank.division_ID,
wp_competitor.first_name,
wp_competitor.last_name,
wp_competitor.global_ID,
wp_divisions.gender,
IF(wp_divisions.age_level IN ('Tiny Kids','Kids','Pre Teen','Teen'),CONCAT('(',wp_divisions.gender,')'),'') as filterGender,
wp_tournaments.`name` as tournament_name,
wp_divisions.name as dname,
CONCAT_WS(' >> ', wp_divisions.division_type, wp_divisions.experience_level, wp_divisions.age_level, wp_divisions.weight_class, wp_divisions.gender) as division,
wp_academies.`name` as academy ,
SUM(wp_grank.points) as totalPoints
FROM
`wp_grank`
LEFT JOIN
wp_competitor
ON
wp_grank.competitor_ID = wp_competitor.ID
LEFT JOIN
wp_tournaments
ON
wp_grank.tournament_ID = wp_tournaments.ID
LEFT JOIN
wp_academies
ON
wp_grank.academy_ID = wp_academies.ID
LEFT JOIN
wp_divisions
ON
wp_grank.division_ID = wp_divisions.ID
WHERE
wp_divisions.ID IN (2) AND
YEAR(wp_tournaments.tournament_date)=2015
Group BY
wp_competitor.ID
ORDER BY
SUM(wp_grank.points) DESC ,wp_competitor.`last_name` ASC

1 个答案:

答案 0 :(得分:1)

通常,最好避免使用UIScreen.mainScreen()。bounds,因为这将返回整个设备屏幕的边界。在分屏多任务处理之前,通常可以假设您的应用程序将占用整个屏幕,现在情况就更长了。您可以改用视图控制器的视图边界。如果您希望视图从顶部到底部的50个点覆盖视图控制器的视图,您可以这样说:

func flashColor() {
    if let vcView = self.view{
        let viewSize: CGRect = CGRect(x:0.0,y:0.0,width:vcView.bounds.size.width,height:vcView.bounds.size.height - 50.0)
        let v = UIView(frame: viewSize)

        v.backgroundColor = colors[i]
        v.alpha = 1

        if i < 4 {
            i += 1
        } else {
            i = 0
        }

        window.addSubview(v)
        UIView.animateWithDuration(1, animations: {
            v.alpha = 0.0
            }, completion: {(finished:Bool) in
                print(i)
                v.removeFromSuperview()
        })

    }
}