上加多并移除,演练代码day一

By admin in 4858.com on 2019年4月16日

 

 

//应用程序代理类

 

 

 

//AppDelegate中的方法都以UIApplicationDelegatez的说道格局

 

     let mview
= UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height:     UIScreen.main.bounds.height))

     let mview
= UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height:     UIScreen.main.bounds.height))

//应用程序类

亟待继承UIView 重写draw 方法

 

 

class AppDelegate: UIResponder, UIApplicationDelegate {

 

     //获取delegate

     //获取delegate

//应用程序窗口,是 AppDelete类的习性

 4858.com 1

        let
delegate  = UIApplication.shared.delegate as! AppDelegate

        let
delegate  = UIApplication.shared.delegate as! AppDelegate

var window: UIWindow?

 

        

        

//应用程序加载成功触发这么些艺术

 

        mview.backgroundColor = UIColor(white: 0.5, alpha: 0.8)

        mview.backgroundColor = UIColor(white: 0.5, alpha: 0.8)

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {

import UIKit

    
//添加tag

    
//添加tag

// Override point for customization after application launch.

class ViewController: UIViewController
{

        mview.tag =
1

        mview.tag =
1

//想再window对象加多对象,就在这几个法子中贯彻

 

上加多并移除,演练代码day一。     //增添视图

     //增加视图

//屏幕类UIScreen

    override func viewDidLoad() {

        delegate.window?.addSubview(mview)

        delegate.window?.addSubview(mview)

//UIScreen.main获得荧屏对象

4858.com ,        super.viewDidLoad()

     //通过tag 从window移除视图

     //通过tag 从window移除视图

//UIScree.main.bounds

        let mview
= myView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))

       
delegate.window?.viewWithTag(1)?.removeFromSuperview()

       
delegate.window?.viewWithTag(1)?.removeFromSuperview()

self.window=UIWindow(frame: UIScreen.main.bounds)

        self.view.addSubview(mview)

self.window?.backgroundColor=#colorLiteral(red: 0.5087699294, green:
0.8069495559, blue: 0.5823518634, alpha: 1)

        

//让Window成为应用程序的主窗口,并使其可知

        let mview2
= myView(frame: CGRect(x: 0, y:200, width: 300,
height: 300))

self.window?.makeKeyAndVisible()

        self.view.addSubview(mview2)

//给window设置跟精算调控器(今后制作精晓)

    }

self.window?.rootViewController=UIViewController()

 

//一般应用程序只有1个window对象

    override func didReceiveMemoryWarning() {

return true

        super.didReceiveMemoryWarning()

}

        // Dispose of any resources that can be
recreated.

//应用程序将要撤除活跃状态是触发

    }

func applicationWillResignActive(_ application: UIApplication) {

    

// Sent when the application is about to move from active to inactive
state. This can occur for certain types of temporary interruptions (such
as an incoming phone call or SMS message) or when the user quits the
application and it begins the transition to the background state.

}

// Use this method to pause ongoing tasks, disable timers, and
invalidate graphics rendering callbacks. Games should use this method to
pause the game.

 

}

 

//已经跻身后台是触发

 

func applicationDidEnterBackground(_ application: UIApplication) {

 

// Use this method to release shared resources, save user data,
invalidate timers, and store enough application state information to
restore your application to its current state in case it is terminated
later.

//自定义View

// If your application supports background execution, this method is
called instead of applicationWillTerminate: when the user quits.

 

}

class 
myView: UIView {

//就要进入前台时接触

    

func applicationWillEnterForeground(_ application: UIApplication) {

    override init(frame: CGRect)
{

// Called as part of the transition from the background to the active
state; here you can undo many of the changes made on entering the
background.

        super.init(frame: frame)

}

     //清除背景颜色

//应用程序已经变得龙精虎猛时接触

        self.backgroundColor = UIColor.clear

func applicationDidBecomeActive(_ application: UIApplication) {

    }

// Restart any tasks that were paused (or not yet started) while the
application was inactive. If the application was previously in the
background, optionally refresh the user interface.

    

}

    required init?(coder aDecoder: NSCoder)
{

//将在结束触发

        super.init(coder: aDecoder)

func applicationWillTerminate(_ application: UIApplication) {

    }

// Called when the application is about to terminate. Save data if
appropriate. See also applicationDidEnterBackground:.

    override func draw(_ rect: CGRect)
{

}

        super.draw(rect)

}

        

何敏  14:54:55

        //获取绘图上下文

class AppDelegate: UIResponder, UIApplicationDelegate {

        guard let context = UIGraphicsGetCurrentContext() else { return 
}

//应用程序窗口,是 AppDelete类的习性

        

var window: UIWindow?

        

//应用程序加载成功触发那几个艺术

        //成立并安装路线

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        let path
= CGMutablePath()

// Override point for customization after application launch.

        path.move(to: CGPoint(x: 10,
y: 10))

//想再window对象加多对象,就在这几个点子中落实

        path.addLine(to: CGPoint(x: 200,
y: 222))

//屏幕类UIScreen

        let secondP
= CGMutablePath()

//UIScreen.main获得荧屏对象

        secondP.move(to: CGPoint(x: 300,
y: 0 ))

//UIScree.main.bounds

        secondP.addLine(to: CGPoint(x: 200,
y: 222))

self.window=UIWindow(frame: UIScreen.main.bounds)

        //设置描线颜色

self.window?.backgroundColor=#colorLiteral(red: 0.5087699294, green:
0.8069495559, blue: 0.5823518634, alpha: 1)

        context.setStrokeColor(UIColor.black.cgColor)

//让Window成为应用程序的主窗口,并使其可见

        //将路线增添到上下文

self.window?.makeKeyAndVisible()

        context.addPath(path)

//给window设置跟精算调控器(今后制作精通)

        context.addPath(secondP)

self.window?.rootViewController=UIViewController()

        //设置线宽

//1般应用程序唯有三个window对象

        context.setLineWidth(10)

//UiView 创立格局

        //开首绘制路线

/*

        context.strokePath()

let redView=UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

    }

redView.backgroundColor=#colorLiteral(red: 1, green: 0.3980397582,
blue: 0.7863847613, alpha: 1)

}

//向window增加1个子视图

 

self.window?.addSubview(redView)

 

//获取荧屏的宽

 

let screenWidth = UIScreen.main.bounds.size.width

//获取显示器的高

let screenHeight=UIScreen.main.bounds.size.height

let greenView = UIView(frame: CGRect(x: screenWidth-100, y: 0, width:
100, height: 100))

greenView.backgroundColor=UIColor.green

self.window?.addSubview(greenView)

let blueView=UIView(frame: CGRect(x: 0, y: screenHeight-100, width: 100,
height: 100))

blueView.backgroundColor=#colorLiteral(red: 0.2392156869, green:
0.6745098233, blue: 0.9686274529, alpha: 1)

self.window?.addSubview(blueView)

let yellowView = UIView(frame: CGRect(x: screenWidth-100, y:
screenHeight-100, width: 100, height: 100))

yellowView.backgroundColor=UIColor.yellow

self.window?.addSubview(yellowView)

let purpleView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height:
100))

//purpleView核心点和window大旨点重合

purpleView.center=(self.window?.center)!

purpleView.backgroundColor=#colorLiteral(red: 0.5568627715, green:
0.3529411852, blue: 0.9686274529, alpha: 1)

self.window?.addSubview(purpleView)*/

let centerView=UIView(frame: CGRect(x: 0, y: 0, width: 200, height:
200))

centerView.backgroundColor=UIColor.red

self.window?.addSubview(centerView)

//UIView常用属性

//alpha 透明度 0.0~1.0

centerView.alpha=1.0

//hidden展现隐形 true  隐藏 false 显示

centerView.isHidden=false

//superView获取到父视图的习性

let fatherView=centerView.superview

fatherView?.backgroundColor=UIColor.yellow

//像centerView增添子视图

let greenView=UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))

greenView.backgroundColor=UIColor.green

//子视图凌驾父视图边界,就把当先部分剪掉

//centerView.clipsToBounds=true

//tag值属性,给视图增加3个唯壹标志

greenView.tag=200

self.window?.addSubview(greenView)

//subView属性,获取子视图属性

let arr=centerView.subviews

let newView=arr[0]

newView.backgroundColor=UIColor.blue

//根据tag值获取视图对象

let newView2=centerView.viewWithTag(200)

newView2?.backgroundColor=UIColor.gray

return true

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 美高梅手机版4858 版权所有