- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是 swift 1.2。我需要为用户创建一个使用我的应用程序的指南。它看起来像:黑色透明屏幕,1 个按钮突出显示,并附有说明如何使用,它是什么。
我一直在寻找解决方案,但仍然卡住了。谁能帮帮我?
谢谢!
最佳答案
如果我理解正确你想要什么,它可以做这样的事情*:
class TutorialView : UIView
{
override init(frame: CGRect)
{
super.init(frame: frame)
self.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.5)
}
convenience init()
{
self.init(frame: CGRectZero)
}
required init?(coder aDecoder: NSCoder)
{
fatalError("init(coder:) has not been implemented")
}
func showFromWindow()
{
let window = UIApplication.sharedApplication().keyWindow!
self.translatesAutoresizingMaskIntoConstraints = false
window.addSubview(self)
window.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[tutorialView]-0-|", options: NSLayoutFormatOptions.DirectionLeftToRight, metrics: nil, views: ["tutorialView": self]))
window.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[tutorialView]-0-|", options: NSLayoutFormatOptions.DirectionLeftToRight, metrics: nil, views: ["tutorialView": self]))
}
func addCommentToTopRightItem(comment: String, afterDelay: NSTimeInterval)
{
let topMargin : Int32 = 54
let rightMargin : Int32 = 24
let height : Int32 = 100
// we need two views - one for arrow and second for text
let commentLabel = UILabel()
let arrowView = UIView()
commentLabel.translatesAutoresizingMaskIntoConstraints = false
arrowView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(commentLabel)
self.addSubview(arrowView)
// setup layout for views
// |^^^^^|
// |^^^^^|arrow|
// |label|_____|
// |_____|
//
// we place center of Y label to the bottom of arrow view
// to an arrow coming out of the middle of text
let metrics = ["topmargin" : NSNumber(int: topMargin), "rightmargin": NSNumber(int: rightMargin),"height" : NSNumber(int: height)]
let views = ["label": commentLabel, "arrow": arrowView]
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-topmargin-[arrow(==height)]", options: NSLayoutFormatOptions.DirectionLeftToRight, metrics: metrics, views: views))
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[label(==height)]", options: NSLayoutFormatOptions.DirectionLeftToRight, metrics: metrics, views: views))
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-rightmargin-[arrow(==height)]-[label]-0-|", options: NSLayoutFormatOptions.DirectionRightToLeft, metrics: metrics, views: views))
self.addConstraint(NSLayoutConstraint(item: commentLabel, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: arrowView, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 1.0))
// configure text label
commentLabel.textColor = UIColor.whiteColor()
commentLabel.numberOfLines = 0
commentLabel.textAlignment = NSTextAlignment.Right
commentLabel.font = UIFont(name: "HelveticaNeue-Light", size: 16)
commentLabel.text = comment
// configure arrow view
self.layoutIfNeeded()
let d : CGFloat = min(arrowView.frame.size.height, arrowView.frame.size.width)
// draw arc line from {0, 1} to {1, 0}
// | /|
// |/_|
let linePath = UIBezierPath()
linePath.moveToPoint(CGPointMake(0, d))
linePath.addCurveToPoint(CGPointMake(d, 0), controlPoint1: CGPointMake(d*0.5, d), controlPoint2: CGPointMake(d, d*0.5))
let lineLayer = CAShapeLayer()
lineLayer.path = linePath.CGPath
lineLayer.strokeColor = UIColor.redColor().CGColor
lineLayer.backgroundColor = UIColor.clearColor().CGColor
lineLayer.fillColor = UIColor.clearColor().CGColor
lineLayer.lineWidth = 2
// draw triangle near {1, 0} point
let trianglePath = UIBezierPath()
trianglePath.moveToPoint(CGPointMake(d, 0))
trianglePath.addLineToPoint(CGPointMake(d - 5, 15))
trianglePath.addLineToPoint(CGPointMake(d + 5, 15))
trianglePath.closePath()
let triangleLayer = CAShapeLayer()
triangleLayer.path = trianglePath.CGPath
triangleLayer.strokeColor = UIColor.redColor().CGColor
triangleLayer.backgroundColor = UIColor.clearColor().CGColor
triangleLayer.fillColor = UIColor.redColor().CGColor
triangleLayer.lineWidth = 2
// line + triangle = arrow :)
arrowView.layer.addSublayer(lineLayer)
arrowView.layer.addSublayer(triangleLayer)
arrowView.alpha = 0.0
commentLabel.alpha = 0.0
UIView.animateWithDuration(0.8, delay: afterDelay, options: UIViewAnimationOptions.AllowAnimatedContent, animations:
{ () -> Void in
arrowView.alpha = 1.0
commentLabel.alpha = 1.0
}, completion: nil)
}
func addButton(title: String, highlighteAfterDelay: NSTimeInterval)
{
// same as before
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(button)
self.addConstraint(NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 1.0))
self.addConstraint(NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: -20.0))
self.addConstraint(NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 120.0))
self.addConstraint(NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 40.0))
button.setTitle(title, forState: UIControlState.Normal)
button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
button.layer.cornerRadius = 20.0
button.layer.masksToBounds = false
button.layer.borderWidth = 1.0
button.layer.borderColor = UIColor.whiteColor().CGColor
button.layer.shadowColor = UIColor.whiteColor().CGColor
button.layer.shadowOpacity = 0.4
button.layer.shadowRadius = 4
button.layer.shadowOffset = CGSizeMake(0, 0)
button.alpha = 0.2
button.enabled = false
UIView.animateWithDuration(0.8, delay: highlighteAfterDelay, options: UIViewAnimationOptions.AllowAnimatedContent, animations:
{ () -> Void in
button.alpha = 1.0
button.enabled = true
}, completion: nil)
}
}
在一些 View Controller 中:
let tutorial = TutorialView()
tutorial.showFromWindow()
tutorial.addCommentToTopRightItem("Tap this button to do something amazing action!", afterDelay: 1.0)
tutorial.addButton("Done", highlighteAfterDelay: 3.0)
结果:
*我没有 1.2 版的编译器,但我认为应该没有太大区别。
关于ios - swift : How to make a Black screen to guidelines for user to use app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32759444/
看完F# Component Design Guidelines ,我没有看到任何评论是否应该声明模块及其类型具有相同的名称。 通常我的项目没有任何循环依赖,所以我不需要创建一个新模块(例如 Infr
我有 .NET 背景,现在正在涉足 Java。 目前,我在设计一个针对错误输入的防御性 API 时遇到了很大的问题。假设我有以下代码(足够接近): public void setTokens(Node
需要有关 Java 接口(interface)命名模式的简短答案。 为什么大多数JAVA接口(interface)名称后缀都有“able”? 例如 java.io.Serializable java.
msvc的cpp核心准则代码分析器告诉我 Warning C26472 Don't use a static_cast for arithmetic conversions. Use brace in
我完全同意下面的导航 假设 Book 详细信息是在 BookDetailActivity 的不同实例中创建的。 book2 详情中压上前的栈是: BookDetailActivity(第 2 本书 -
我已经查看了应用评论的官方应用指南,但可以得到答案。我正在开发一个应用程序,它将获取用户的电话联系人并将它们存储在我的服务器上。然后,这些联系人将对某些其他应用程序用户可见。假设我提醒用户他们的联系人
我得到了这个设置: ... 现在,当 View 未满并且不需要滚动条时 - 一切都按预期工作 - 图像相对于屏幕尺寸为 35
我得到了这个设置: ... 现在,当 View 未满并且不需要滚动条时 - 一切都按预期工作 - 图像相对于屏幕尺寸为 35
如何以编程方式创建 ConstraintLayouts 和 Guidelines?我已经尝试使用以下代码创建一个简单的布局,该布局使用指南将 View 锚定到屏幕中间,但它在屏幕左侧呈现红色“v” V
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 7 年前。 Improve
这个问题在这里已经有了答案: How Non-Member Functions Improve Encapsulation (8 个答案) 关闭 5 年前。 C++ Core Guidelines
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。 visit the help center 帮助澄清这个问题以便重新打开它。 11
我想尝试使用 Core Guidelines checker tool在 VS2015 下的 C++11/14 项目上。 在我的代码中,我使用了很多来自 Boost 的库,它们触发了很多警告。我不关心
App Store Review Guidelines 说:“以任何方式或形式下载代码的应用程序将被拒绝。” 我想制作一个使用挑战-响应进行身份验证的应用程序。该应用程序具有一套基本算法,例如 SHA
最近尝试实现 Constraint Layout 但我发现 Barrier 和 Guideline 工作方式相同。 两者都像分隔线一样工作.它们之间有什么区别吗? 最佳答案 何时使用障碍 假设您有两个
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我正在尝试找到一种简单的方法来为 Plottable.js 中的 GuideLineLayer 着色。 到目前为止我尝试了以下方法。 1) 尝试在 onAnchor() 内使用 attr()这会将 a
我正在尝试使用以下方法设置新代理: java -javaagent:agent.jar 当我运行时,我看到 java 使用消息。 list .MF: Manifest-Version: 1.0 Cre
有问题的应用程序将包含用于解锁功能的典型不可更新订阅模型,但也将有另一种机制来访问其他功能。 此应用程序将允许用户购买(假设为消耗品)在固定期限内为另一用户访问完整功能。当然,该应用程序必须在其自己的
我下载了一些数据并将其保存到 Library/PrivateDocuments 目录。我在这个 Library/PrivateDocuments 目录中下载的每个文件都设置了“不备份”属性。苹果仍然说
我是一名优秀的程序员,十分优秀!