- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建的内容的屏幕截图:
注意:如果您决定运行该项目,则无需查看下面的代码,因为我在下面发布的所有类都位于 dropbox 压缩项目文件内。
底部的每个方 block 都选择不同的颜色,并且有一个不可见的方 block 选择绿色方 block 右侧的形状类型。用户选择其中一种形状后,用户将能够在屏幕的特定部分进行绘制。
整个项目:https://www.dropbox.com/s/f9pr0wo0j74iw4a/XcodeSwiftProject99999.zip?dl=0
如果您运行该项目,创建一个帐户,然后单击登录,然后单击其中一行,然后单击彩色框之一(红色和绿色方 block ),应用程序将崩溃并收到以下错误消息:
2016-03-11 17:06:43.580 finalProject2[11487:1058358] <UIView: 0x7faba1677710; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = <NSArray: 0x7faba1658d90>; layer = <CALayer: 0x7faba16563f0>>'s window is not equal to <finalProject2.RowTableViewController: 0x7faba165a3c0>'s view's window!
File slot 1
File slot 2
File slot 3
File slot 4
File slot 5
File slot 6
File slot 7
File slot 8
File slot 9
File slot 10
File slot 11
File slot 12
2016-03-11 17:06:44.746 finalProject2[11487:1058358] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x7faba16b7d60>)
MainProject场景类:
import UIKit
weak var FirstFileNameTextField: UILabel!
enum ShapeType: String
{
case Line = "Line"
case Ellipse = "Ellipse"
case Rectangle = "Rectangle"
case FilledEllipse = "Filled Ellipse"
case FilledRectangle = "Filled Rectangle"
case Scribble = "Scribble"
}
let shapes: [ShapeType] = [ .Line, .Ellipse, .Rectangle, .FilledEllipse, .FilledRectangle, .Scribble ]
class MainProjectScene: UIViewController
{
var row: Row?
@IBAction func PressedSaveAs(sender: UIButton) //this is the save as function that I would like to know how to change
{
//1. Create the alert controller.
var alert = UIAlertController(title: "Name/rename your file:", message: "Enter a filename to name/rename and save your file", preferredStyle: .Alert)
//2. Add the text field. You can configure it however you need.
alert.addTextFieldWithConfigurationHandler({ (textField) -> Void in
textField.text = "Your file name"
})
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:
{
(action) -> Void in
let textField = alert.textFields![0] as UITextField
print("Text field: \(textField.text)")
// rows.cell.textLabel?.text = textField.text
CurrentFileName = textField.text!
rows[IndexPath.row].FileName = textField.text!
rows[IndexPath.row].UserText = self.TextUserScrollEdit.text!
}))
// 4. Present the alert.
self.presentViewController(alert, animated: true, completion: nil)
// rows[indexPath.row].FileName = rows.cell.textLabel?.text
// rows[i] = textField.text
// if let detailViewController = segue.destinationViewController as? MainProjectScene {
// if let cell = sender as? UITableViewCell {
// if let indexPath = self.tableView.indexPathForCell(cell) {
// detailViewController.row = rows[indexPath.row]
}
override func viewWillAppear(animated: Bool)
{
if let r = row
{
row!.FileName = r.FileName
row!.QuartzImage = r.QuartzImage
row!.UserText = r.UserText
rows[IndexPath.row].UserText = self.TextUserScrollEdit.text! }
}
override func viewDidLoad()
{
super.viewDidLoad()
TextUserScrollEdit.text = rows[IndexPath.row].UserText
// FacebookButton.addTarget(self, action: "didTapFacebook", forControlEvents: .TouchUpInside)
}
@IBOutlet weak var TextUserScrollEdit: UITextView!
@IBOutlet weak var NewFileButton: UIButton!
@IBOutlet weak var TwoDQuartzButton: UIButton!
@IBOutlet weak var YouTubeButton: UIButton!
@IBOutlet weak var TwitterButton: UIButton!
@IBOutlet weak var OpenFileButton: UIButton!
@IBOutlet weak var SnapChatButton: UIButton!
@IBOutlet weak var FacebookButton: UIButton!
@IBAction func PressedTwoDQuartzButton(sender: UIButton) {
}
@IBAction func PressedSnapchatButton(sender: UIButton){
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.snapchat.com/")!)
}
@IBAction func PressedYouTubeButton(sender: UIButton) {
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.youtube.com/")!)
}
@IBOutlet weak var InstagramButton: UIButton!
@IBAction func PressedFacebookButton(sender: UIButton) {
UIApplication.sharedApplication().openURL(NSURL(string: "http://www.facebook.com")!)
}
@IBAction func PressedInstagramButton(sender: UIButton) {
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.instagram.com/")!)
}
@IBAction func PressedTwitterButton(sender: UIButton) {
UIApplication.sharedApplication().openURL(NSURL(string: "https://twitter.com/")!)
}
@IBOutlet weak var SaveAsButton: UIButton!
// @IBOutlet weak var shapeButton: ShapeButton!
@IBOutlet weak var canvas: CanvasView!
@IBOutlet var colorButtons: [UIButton]!
@IBOutlet weak var shapeButton: ShapeButton!
@IBAction func selectColor(sender: UIButton) {
UIView.animateWithDuration(0.5, delay: 0.0,
usingSpringWithDamping: CGFloat(0.25),
initialSpringVelocity: CGFloat(0.25),
options: UIViewAnimationOptions.CurveEaseInOut, animations: {
for button in self.colorButtons {
button.frame.origin.y = self.view.bounds.height - 58
}
sender.frame.origin.y -= 20
}, completion: nil)
canvas.color = sender.backgroundColor!
shapeButton.color = sender.backgroundColor!
}
@IBAction func selectShape(sender: ShapeButton) {
let title = "Select Shape"
let alertController = UIAlertController(title: title, message: nil, preferredStyle: .ActionSheet)
for shape in shapes {
let action = UIAlertAction(title: shape.rawValue, style: .Default) { action in
sender.shape = shape
self.canvas.shape = shape
}
alertController.addAction(action)
}
presentViewController(alertController, animated: true, completion: nil)
}
}
ShapeButton 类:
import UIKit
class ShapeButton: UIButton {
let shapes: [ShapeType] = [ .Line, .Ellipse, .Rectangle, .FilledEllipse, .FilledRectangle, .Scribble ]
var shape: ShapeType = .Line {
didSet {
setNeedsDisplay()
}
}
var color: UIColor = UIColor.blueColor() {
didSet {
setNeedsDisplay()
}
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
let context = UIGraphicsGetCurrentContext()
CGContextSetStrokeColorWithColor(context, color.CGColor)
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextSetLineWidth(context, 2)
let x1: CGFloat = 5
let y1: CGFloat = 5
let x2: CGFloat = frame.width - 5
let y2: CGFloat = frame.height - 5
let rect = CGRect(x: x1, y: y1 + 5, width: frame.width - 10, height: frame.height - 20)
switch shape {
case .Line:
CGContextMoveToPoint(context, x1, y1)
CGContextAddLineToPoint(context, x2, y2)
CGContextStrokePath(context)
case .Ellipse:
CGContextStrokeEllipseInRect(context, rect)
case .Rectangle:
CGContextStrokeRect(context, rect)
case .FilledEllipse:
CGContextFillEllipseInRect(context, rect)
case .FilledRectangle:
CGContextFillRect(context, rect)
case .Scribble:
CGContextMoveToPoint(context, x1, y1)
CGContextAddCurveToPoint(context,
x1 + 80, y1 - 10, // the 1st control point
x2 - 80, y2 + 10, // the 2nd control point
x2, y2) // the end point
CGContextStrokePath(context)
}
}
}
Canvas View 类:
import UIKit
/*
This program is for Xcode 6.3 and Swift 1.2
*/
class CanvasView: UIView {
var shape: ShapeType = .Line
var color: UIColor = UIColor.blueColor()
var first :CGPoint = CGPointZero
var last :CGPoint = CGPointZero
var points: [CGPoint] = []
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
let context = UIGraphicsGetCurrentContext()
CGContextSetStrokeColorWithColor(context, color.CGColor)
CGContextSetFillColorWithColor(context, color.CGColor)
let rect = CGRect(x: first.x, y: first.y, width: last.x - first.x, height: last.y - first.y)
switch shape {
case .Line:
CGContextMoveToPoint(context, first.x, first.y)
CGContextAddLineToPoint(context, last.x, last.y)
CGContextStrokePath(context)
case .Ellipse:
CGContextStrokeEllipseInRect(context, rect)
case .Rectangle:
CGContextStrokeRect(context, rect)
case .FilledEllipse:
CGContextFillEllipseInRect(context, rect)
case .FilledRectangle:
CGContextFillRect(context, rect)
case .Scribble:
CGContextMoveToPoint(context, first.x, first.y)
for p in points {
CGContextAddLineToPoint(context, p.x, p.y)
}
CGContextStrokePath(context)
}
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
first = touch.locationInView(self)
last = first
points.removeAll(keepCapacity: true)
if shape == .Scribble {
points.append(first)
}
setNeedsDisplay()
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
last = touch.locationInView(self)
if shape == .Scribble {
points.append(last)
}
setNeedsDisplay()
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
last = touch.locationInView(self)
if shape == .Scribble {
points.append(last)
}
setNeedsDisplay()
}
}
override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
}
}
最佳答案
在 Storyboard中,转到 MainProjectScene
并右键单击 CanvasView
。
您将有两个 CanvasView
的引用导出。
删除两个引用 socket 。现在再次选择 CanvasView
并转到身份检查器并确保 View 的类是 CanvasView
保留主 Storyboard和 MainProjectScene
并将您的 CanvasView
链接到 Storyboard中的 View ,如下所示
这解决了问题。
我只是向您介绍一下您刚刚遇到的问题的一些见解。您可能首先在代码中创建了一个 View 导出并链接它,然后将其删除。那么您必须再次创建它并链接它。执行此操作后,您的 View 上将有 2 个引用点。您需要删除刚刚删除的那个,否则代码将崩溃。
关于ios - Swift xcode 错误 : load controller is not allowed and autoresize not equal to views window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35952516/
在 Sitecore 中,我尝试在线路管理器中创建分段列表。但是,当我选择条件时,我对“等于”、“不区分大小写等于”和“不不区分大小写等于”感到非常困惑? 谁能给我解释一下其中的区别吗? 谢谢! 最佳
基本上,我想知道在这种情况下我是否应该听 ReSharper... 您认为与字符进行比较应该使用 Char.Equals(char),因为它可以避免拆箱,但 Resharper 建议使用 Object
假设 equals() 是可传递的;我知道如果 x 和 y 有平等的双边协议(protocol),那么其中一个,比如 y,不会单独与第三类 z 签订协议(protocol)。 但是如果我们遇到 x.e
我是 Haskell 新手,正在阅读: http://www.seas.upenn.edu/~cis194/spring13/lectures/01-intro.html 它指出“在 Haskell
阅读有关 C# 中的字符串比较的文章,我发现有很多方法可以比较 2 个字符串以查看它们是否相等。 我习惯了来自 C++ 的 == 但我了解到,如果你将一个对象与一个字符串进行比较,那么 == 默认为引
我有一个 Point 类和一个 MinesweeperSquare 类,后者是前者的子类。如果我重写后者的 equals 方法,就像这样: if (!(obj instanceof Minesweep
我想知道,如果我们有 if-else 条件,那么检查什么在计算上更有效:使用等于运算符或不等于给运营商?有什么区别吗? 例如,以下哪一项在计算上是高效的,下面的两种情况都会做同样的事情,但哪一种更好(
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
某些框架(例如 guice )在某些情况下需要创建 注解接口(interface)的实现类 . 好像有一个区别 Annotation.equals(Object) 之间和 Object.equals(
从三个变量开始,都是System.DateTime。 a: 10/2/2009 2:30:00 PM b: 10/2/2009 2:30:00 PM c: 10/2/2009 2:30:00 PM 相
我实现了一个 PagedModel 类来包装 IEnumerable,为我的 MVC 应用程序中的网格提供分页数据。我使用 Resharper 自动生成的 Equality 代码告诉它检查数据、总行数
正如问题所述。理想情况下,答案应该是 false,因为它将使用 Object#equal,这只是引用比较。 String cat = new String("cat"); String
我想知道以下两个选项中哪一个在速度方面最有效。它们之间可能只有很小的区别(或者根本没有区别?)但是由于我每天使用该代码片段 30 次,所以我想知道这里的“最佳实践”是什么 :) 选项 1: if (s
我有一个以年龄和姓名作为实例成员的基类,以及带有奖金的派生类。我在派生类中重写 equals 。我知道 Java 中只有一个基类时 equals 是如何工作的。但我无法理解继承的情况下它是如何工作的。
==之间的区别和 ===是前者仅检查值(1 == "1" 将返回 true),后者是否检查值并另外检查类型(1 === "1" 将返回 false,因为 number 不是字符串)。 比较对象意味着比
这是一个理论问题。我有一个我自己设计的对象,其中包含一堆变量、方法等。我覆盖了 toString 方法,主要用于记录目的,以返回变量的值。在我看来,比较此对象实例的最简单和最直接的方法是比较从 toS
我是 Java 编程的初学者。目前我正在 this 阅读关于继承和 equals 方法的内容。页。到目前为止,我理解解释: Compare the classes of this and otherO
当 IntelliJ 建议我更正以下内容时,我正在编写代码: objectOne.equals(objectTwo); 告诉我方法调用 equals 可能会产生旧的 java.lang.NullPoi
我尝试创建一个允许在 Java 中使用类似元组的结构的元组类。元组中两个元素的一般类型分别是 X 和 Y。我尝试为此类覆盖正确的等号。 事情是,我知道 Object.equals 属于默认值,它仍然根
可以用和比较字符串类似的方式来比较序列。如果两个序列的长度相同,并且对应元素都相等,equal() 算法会返回 true。有 4 个版本的 equal() 算法,其中两个用 == 运算符来比较元素,另
我是一名优秀的程序员,十分优秀!