我有一个CAShapeLayer()顶部有渐变的动画,但不知何故它看起来如下图所示:

怎么看起来是这个样子?
我的代码:
override func viewDidLayoutSubviews() {
displayLine()
}
override func viewDidAppear(_ animated: Bool) {
animateStroke()
}
func displayLine() {
let trackLayer = CAShapeLayer()
let rect = CGRect(x: topView.frame.width * 0.15, y: topView.frame.size.height / 1.5, width: topView.frame.width * 0.7, height: 2)
let path = UIBezierPath(roundedRect: rect, cornerRadius: 1)
trackLayer.path = path.cgPath
trackLayer.strokeColor = UIColor.groupTableViewBackground.cgColor
trackLayer.lineWidth = 3
trackLayer.fillColor = UIColor.clear.cgColor
shapeLayer.path = path.cgPath
shapeLayer.strokeColor = UIColor.green.cgColor
shapeLayer.lineWidth = 4
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeEnd = 0
topView.layer.addSublayer(trackLayer)
topView.layer.addSublayer(shapeLayer)
let …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试在页面刷新时滚动到顶部。到目前为止,我已经能够在路线更改时实现滚动到顶部,但不能在页面刷新时实现 - 不知何故反应总是恢复其先前的位置。我怎样才能防止这种情况发生?
这就是我实现滚动到顶部的方式(认为window.scrollTo(0, 0)内部componenDidMount()会有所帮助,但它没有):
class ScrollToTop extends Component {
componentDidMount() {
window.scrollTo(0, 0);
}
componentDidUpdate(prevProps, prevState, snapshot) {
if (this.props.location.pathname !== prevProps.location.pathname) {
window.scrollTo(0, 0);
}
}
render() {
return null;
}
}
export default withRouter(ScrollToTop);
Run Code Online (Sandbox Code Playgroud)
class App extends Component {
render() {
return (
<BrowserRouter>
<ScrollToTop/>
<Header/>
<Home/>
<Projects/>
<div className="follow-cursor"/>
</BrowserRouter>
);
}
}
export default App;
Run Code Online (Sandbox Code Playgroud) 我正在使用 an UIPageViewController,我的目的是在单击UIButton其中一个UIViewController. 我已经用谷歌搜索了我的问题并找到了一些类似的线索,但我无法弄清楚答案。
例如,我的第二个按钮UIViewController vc2应将视图更改为vc3。
根页面视图控制器
import UIKit
class RootPageViewController: UIPageViewController, UIPageViewControllerDataSource {
lazy var viewControllerList:[UIViewController] = {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc1 = sb.instantiateViewController(withIdentifier: "timelineView")
let vc2 = sb.instantiateViewController(withIdentifier: "mainView")
let vc3 = sb.instantiateViewController(withIdentifier: "addView")
return [vc1, vc2, vc3]
}()
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
let secondViewController = viewControllerList[1]
self.setViewControllers([secondViewController], direction: .forward, animated: false, completion: nil)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore …Run Code Online (Sandbox Code Playgroud) 我为 Firestore 数据库设置了以下规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /collections/{document=**} {
allow read;
allow write: if isAdmin();
}
match /general/{document=**} {
allow read;
allow write: if isAdmin();
}
match /inquiries/{document=**} {
allow write;
allow read: if isAdmin();
}
match /orders/{document=**} {
allow write;
allow read: if isAdmin() || resource.data.userID == request.auth.uid;
}
match /products/{document=**} {
allow read;
allow write: if isAdmin();
}
match /users/{userId} {
allow write, read: if belongsTo(userId);
}
function belongsTo(userId) {
return request.auth.uid …Run Code Online (Sandbox Code Playgroud) 我将 PageViewController 添加到普通视图控制器作为viewDidAppear()HomeViewController 中的子视图,如下所示:
if showTutorial == false {
addChild(controller)
controller.view.frame = view.frame
view.addSubview(controller.view)
controller.didMove(toParent: self)
}
Run Code Online (Sandbox Code Playgroud)
它有效,但我不知道如何再次删除它- PageViewController 包含一个在其页面中导航的按钮。到达某个页面时,我想通过单击 PageViewController 内部的按钮再次从 HomeViewController 中删除 PageViewController。
我怎样才能这样做呢?
PageViewController 内部的按钮:
@objc func buttonAction(sender: UIButton!) {
if currentTutorialPage != 4 {
currentTutorialPage += 1
self.setViewControllers([self.viewControllerList[currentTutorialPage]], direction: .forward, animated: false, completion: nil)
view.bringSubviewToFront(nextButton)
view.bringSubviewToFront(prevButton)
} else {
tutorialSeen = true
defaults.set(tutorialSeen, forKey: "tutorialSeen")
}
}
Run Code Online (Sandbox Code Playgroud) 我使用 Firestore 来存储我的 Angular 应用程序的数据。我创建了一个服务并读取数据,例如:
retrieveCollectionColors(name) {
this.db.collectionGroup('collection-colors', ref => ref.where('product', '==', name))
.valueChanges().subscribe( (val: []) => {
this.collectionColors.next(val);
});
}
Run Code Online (Sandbox Code Playgroud)
如何捕获错误,如果发生错误,如何重试查询?
javascript firebase typescript angular google-cloud-firestore
I'm trying to create an object that takes its name from another property.
const slide = 0;
const result = 'Hello';
const object = { slide: result };
How I want the object to look like in the end:
{ 0: result }
Run Code Online (Sandbox Code Playgroud)
我该如何实现?因为我使用它的方式,所以名称始终是“ slide”,但是我希望它以0作为名称。
我使用以下方法在一段时间后更改属性:
switchColors() {
this.interval = setInterval( () => {
some code;
}, 700);
}
Run Code Online (Sandbox Code Playgroud)
它可以工作,但是有时这种方法在闪烁,跳跃等方面似乎并不可靠。
是否有另一种更好的方法来实现类似的行为?
ios ×3
javascript ×3
swift ×3
typescript ×3
angular ×2
cashapelayer ×1
firebase ×1
html ×1
reactjs ×1