The options parameter for UIView.transitionFromView:toView:duration:options:completion: no longer support | operation. I did some survey for the reason for this and found out that UIViewAnimationOptions is now conform to OptionSetType protocol since Swift 2. That is to say you need to call union or intersect defined by the implementation of OptionSetType protocol.
In Flo project, you need to change the line of code calling UIView.transitionFromView to
In this line, UIView.transitionFromView(GraphView, ... I get the error "Cannot convert value of type ‘GraphView.Type’ to expected argument type ‘UIView’, which makes sense, but I’m not sure what to do about it. Any tips for me?
Anywhere you see old code showing the bit mask or | operation, it’s probably changed to being an OptionSetType, which will be an array of all the options.
It looks neater than the bit mask operation (I think) :).
I may be misunderstanding, but I seem to be having a separate issue from that.
I already changed my code to the array syntax based on an earlier comment. The part that seems to be producing my error is the first parameter to transitionFromView , which is graphView. Xcode is telling me it’s expecting a UIView rather than a GraphView type.
Sorry if I am missing something with your explanation, and thanks for your help!
Just wonder why you don’t use CAGradientLayer when you create a gradient layer. It’s quite simple than using CGContextDrawLinearGradient function. Here’s are my solution:
Thank you for adding this @tanvu. Yes, an alternative is CAGradientLayer, and I would encourage people to look into CALayers.
It’s always good to know about alternatives and be able to use either equally well. In this particular situation, where I am drawing into a context already, I personally would use CGContextDrawLinearGradient as I have points in the method all worked out for masking.
Hello,
I was wandering what I would have to add to the ViewContoller.swift if I would like to change the data by a button. So like show the monthly data and then the graph shows the new data. @IBAction func MonatAnzeigen(sender: AnyObject) { graphView.graphPoints = [320,321,333,310,219,284,312,313, 321, 164, 192, 430, 130, 122,231,123,318,275,391,258,283,192,371,293,371,263,192,374,400,300,123] setupGraphDisplay() }
If I impelemt the func like this only the labels change due to the setupGraphDisplay. How do I refresh the View as well?
for i in 1…<self.graphPoints.count {
let nextPoint = CGPoint(x:columnXPoint(i),
y:columnYPoint(graphPoints[i]))
graphPath.addLineToPoint(nextPoint)
I am getting the error variable used within its own initial value… Looked all around and tried to mess with it myself. Any help would be greatly appreciated. thanks
@icculus - the for loop you’ve written above doesn’t make sense.
This code:
let graphPath = UIBezierPath()
graphPath.moveToPoint(CGPoint(x:columnXPoint(0),
y:columnYPoint(graphPoints[0])))
for i in 1..<graphPoints.count {
let nextPoint = CGPoint(x:columnXPoint(i),
y:columnYPoint(graphPoints[i]))
graphPath.addLineToPoint(nextPoint)
}
This is a great discussion, and it really helped point me in the right direction. Swift 3 introduced a number of additional changes to the UIView.transition syntax, and the resulting code is:
In the GraphView class, inside the draw(_ rect:) function we use addClip() to add the rounded corners. I understand how this works, for the documentation explains it pretty clearly:
This method modifies the visible drawing area of the current graphics context.
I do have one question though: How is this operation able to work before the line: let context = UIGraphicsGetCurrentContext()
This throws me a curve, in that we can affect the context before we get the context back. How does this work?
Unless the context is created as soon as the draw(rect:) function is called.