parent
6cccb75b0c
commit
5a79705fa5
@ -0,0 +1,21 @@ |
||||
{ |
||||
"images" : [ |
||||
{ |
||||
"filename" : "arrow-right.png", |
||||
"idiom" : "universal", |
||||
"scale" : "1x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "2x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "3x" |
||||
} |
||||
], |
||||
"info" : { |
||||
"author" : "xcode", |
||||
"version" : 1 |
||||
} |
||||
} |
After Width: | Height: | Size: 248 B |
@ -0,0 +1,21 @@ |
||||
{ |
||||
"images" : [ |
||||
{ |
||||
"filename" : "crown.png", |
||||
"idiom" : "universal", |
||||
"scale" : "1x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "2x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "3x" |
||||
} |
||||
], |
||||
"info" : { |
||||
"author" : "xcode", |
||||
"version" : 1 |
||||
} |
||||
} |
After Width: | Height: | Size: 590 B |
@ -0,0 +1,21 @@ |
||||
{ |
||||
"images" : [ |
||||
{ |
||||
"filename" : "earth.png", |
||||
"idiom" : "universal", |
||||
"scale" : "1x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "2x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "3x" |
||||
} |
||||
], |
||||
"info" : { |
||||
"author" : "xcode", |
||||
"version" : 1 |
||||
} |
||||
} |
After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1,21 @@ |
||||
{ |
||||
"images" : [ |
||||
{ |
||||
"filename" : "location.png", |
||||
"idiom" : "universal", |
||||
"scale" : "1x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "2x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "3x" |
||||
} |
||||
], |
||||
"info" : { |
||||
"author" : "xcode", |
||||
"version" : 1 |
||||
} |
||||
} |
After Width: | Height: | Size: 1.0 KiB |
@ -0,0 +1,64 @@ |
||||
import SwiftUI |
||||
|
||||
struct GrowingTextInputView: View { |
||||
init(text: Binding<String?>, placeholder: String) { |
||||
self._text = text |
||||
self.placeholder = placeholder |
||||
} |
||||
|
||||
@Binding var text: String? |
||||
@State var focused: Bool = false |
||||
@State var contentHeight: CGFloat = 0 |
||||
|
||||
let placeholder: String? |
||||
let minHeight: CGFloat = 39 |
||||
let maxHeight: CGFloat = 150 |
||||
|
||||
var countedHeight: CGFloat { |
||||
min(max(minHeight, contentHeight), maxHeight) |
||||
} |
||||
|
||||
var body: some View { |
||||
ZStack(alignment: .topLeading) { |
||||
Color.white |
||||
ZStack(alignment: .topLeading) { |
||||
placeholderView |
||||
TextViewWrapper(text: $text, focused: $focused, contentHeight: $contentHeight) |
||||
}.padding(.horizontal, 4) |
||||
}.frame(height: countedHeight) |
||||
} |
||||
|
||||
var placeholderView: some View { |
||||
ViewBuilder.buildIf( |
||||
showPlaceholder ? |
||||
placeholder.map { |
||||
Text($0) |
||||
.foregroundColor(.gray) |
||||
.font(.system(size: 16)) |
||||
.padding(.vertical, 8) |
||||
.padding(.horizontal, 4) |
||||
} : nil |
||||
) |
||||
} |
||||
|
||||
var showPlaceholder: Bool { |
||||
if let text=self.text{ |
||||
return !focused&&text.isEmpty |
||||
}else{ |
||||
return false |
||||
} |
||||
} |
||||
} |
||||
|
||||
#if DEBUG |
||||
struct GrowingTextInputView_Previews: PreviewProvider { |
||||
@State static var text: String? |
||||
|
||||
static var previews: some View { |
||||
GrowingTextInputView( |
||||
text: $text, |
||||
placeholder: "Placeholder" |
||||
) |
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,72 @@ |
||||
import SwiftUI |
||||
|
||||
struct TextViewWrapper: UIViewRepresentable { |
||||
|
||||
init(text: Binding<String?>, focused: Binding<Bool>, contentHeight: Binding<CGFloat>) { |
||||
self._text = text |
||||
self._focused = focused |
||||
self._contentHeight = contentHeight |
||||
} |
||||
|
||||
@Binding var text: String? |
||||
@Binding var focused: Bool |
||||
@Binding var contentHeight: CGFloat |
||||
|
||||
// MARK: - UIViewRepresentable |
||||
|
||||
func makeUIView(context: Context) -> UITextView { |
||||
let textView = UITextView() |
||||
textView.delegate = context.coordinator |
||||
textView.font = .systemFont(ofSize: 16) |
||||
textView.backgroundColor = .clear |
||||
textView.autocorrectionType = .no |
||||
return textView |
||||
} |
||||
|
||||
func makeCoordinator() -> Coordinator { |
||||
Coordinator(text: $text, focused: $focused, contentHeight: $contentHeight) |
||||
} |
||||
|
||||
func updateUIView(_ uiView: UITextView, context: Context) { |
||||
uiView.text = text |
||||
} |
||||
|
||||
class Coordinator: NSObject, UITextViewDelegate { |
||||
|
||||
init(text: Binding<String?>, focused: Binding<Bool>, contentHeight: Binding<CGFloat>) { |
||||
self._text = text |
||||
self._focused = focused |
||||
self._contentHeight = contentHeight |
||||
} |
||||
|
||||
@Binding private var text: String? |
||||
@Binding private var focused: Bool |
||||
@Binding private var contentHeight: CGFloat |
||||
|
||||
// MARK: - UITextViewDelegate |
||||
|
||||
func textViewDidChange(_ textView: UITextView) { |
||||
text = textView.text |
||||
contentHeight = textView.contentSize.height |
||||
} |
||||
|
||||
func textViewDidBeginEditing(_ textView: UITextView) { |
||||
focused = true |
||||
} |
||||
|
||||
func textViewDidEndEditing(_ textView: UITextView) { |
||||
focused = false |
||||
contentHeight = text == nil ? 0 : textView.contentSize.height |
||||
} |
||||
} |
||||
} |
||||
|
||||
#if DEBUG |
||||
struct TextViewWrapper_Previews: PreviewProvider { |
||||
@State static var text:String? |
||||
|
||||
static var previews: some View { |
||||
TextViewWrapper(text: $text, focused: .constant(false), contentHeight: .constant(0)) |
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,162 @@ |
||||
// |
||||
// SendView.swift |
||||
// Weibo |
||||
// |
||||
// Created by Qihua Pan on 2020/8/20. |
||||
// Copyright © 2020 Qihua Pan. All rights reserved. |
||||
// |
||||
|
||||
import SwiftUI |
||||
import CoreData |
||||
|
||||
import Alamofire |
||||
import SwiftyJSON |
||||
struct SendView: View { |
||||
|
||||
@Environment(\.managedObjectContext) var contenxt:NSManagedObjectContext |
||||
|
||||
@EnvironmentObject var user:User |
||||
|
||||
var flag={} |
||||
|
||||
@State var text:String?="" |
||||
@State private var textStyle = UIFont.TextStyle.body |
||||
|
||||
//全局记录高度的值 |
||||
// @State var value:CGFloat = 0 |
||||
|
||||
let domain="https://sukura.com" |
||||
|
||||
@State var showAlert=false |
||||
|
||||
@State var showTip=false |
||||
|
||||
var body: some View { |
||||
VStack { |
||||
if self.showTip{ |
||||
Spacer() |
||||
LoadView() |
||||
Spacer() |
||||
} |
||||
else{ |
||||
HStack { |
||||
Button(action: { |
||||
self.flag() |
||||
|
||||
// self.alert(isPresented: self.$showAlert, content: { |
||||
// Alert(title: Text("fuck"),primaryButton: .destructive(Text("确认")) { print("转出中...") }, secondaryButton: .cancel()) |
||||
// |
||||
// }).navigationBarTitle(Text("Alert")) |
||||
}) { |
||||
Text("取消") |
||||
.foregroundColor(Color.black) |
||||
} |
||||
Spacer() |
||||
VStack { |
||||
Text("发微博") |
||||
// Text(self.$user.name).foregroundColor(Color.gray) |
||||
Text("用户7450769290") |
||||
.foregroundColor(Color.gray) |
||||
} |
||||
Spacer() |
||||
|
||||
Button(action: { |
||||
print("send") |
||||
if let access_token=self.user.access_token,let text=self.text{ |
||||
self.showTip=true |
||||
|
||||
AF.request("https://api.weibo.com/2/statuses/share.json",method: .post,parameters: ["access_token":access_token,"status":"\(text):\(self.domain)"]).responseJSON { response in |
||||
self.showTip=false |
||||
if let data=response.data,let json = try? JSON(data: data){ |
||||
print("分享微博信息返回\(json)") |
||||
self.flag() |
||||
}else{ |
||||
print("发送微博失败") |
||||
self.alert(isPresented: self.$showAlert, content: { |
||||
Alert(title: Text("错误提示").foregroundColor(Color.red),message: Text("发送微博失败,请联系管理员")) |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
}){ |
||||
Text("发送") |
||||
.foregroundColor(Color.gray) |
||||
} |
||||
.padding(.all, 5.0) |
||||
.frame(width: 50.0) |
||||
.background(/*@START_MENU_TOKEN@*/Color.orange/*@END_MENU_TOKEN@*/) |
||||
.cornerRadius(30) |
||||
|
||||
} |
||||
.padding(.horizontal) |
||||
.background(Color(red: 229/255, green: 230/255, blue: 229/255, opacity: 1.0)) |
||||
|
||||
|
||||
// MultiLineTextView(text: self.$text, textStyle: self.$textStyle) |
||||
GrowingTextInputView(text: $text, placeholder: "分享新鲜事...") |
||||
HStack { |
||||
|
||||
Button(action: { |
||||
|
||||
}) { |
||||
HStack(spacing: 0.0) { |
||||
Image("location").foregroundColor(Color(red: 148/255, green: 148/255, blue: 148/255, opacity: 1.0)) |
||||
Text("你在哪里?").foregroundColor(Color.gray) |
||||
} |
||||
} |
||||
.padding(.all, 10.0) |
||||
// .background(Color.red) |
||||
.background(Color(red: 228/255, green: 228/255, blue: 228/255, opacity: 1.0)) |
||||
.cornerRadius(20) |
||||
Spacer() |
||||
if self.text!.count>0{ |
||||
Text("\(self.text!.count)").font(.title) |
||||
} |
||||
|
||||
Button(action: { |
||||
|
||||
}) { |
||||
HStack(spacing: 0.0) { |
||||
Image("earth") |
||||
Text("公开") |
||||
} |
||||
}.padding(.all, 10.0) |
||||
// .background(Color.red) |
||||
.background(Color(red: 228/255, green: 228/255, blue: 228/255, opacity: 1.0)) |
||||
|
||||
.cornerRadius(/*@START_MENU_TOKEN@*/20.0/*@END_MENU_TOKEN@*/) |
||||
} |
||||
.padding(.horizontal) |
||||
Spacer() |
||||
} |
||||
// .offset(y : -value) |
||||
// .animation(.spring()).onAppear(perform: { |
||||
//键盘抬起 |
||||
// NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: OperationQueue.current) { (noti) in |
||||
// let value = noti.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect |
||||
// let height = value.height |
||||
// self.value = height - UIApplication.shared.windows.first!.safeAreaInsets.bottom |
||||
// } |
||||
// //键盘收起 |
||||
// NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: OperationQueue.current) { (noti) in |
||||
// self.value = 0 |
||||
// } |
||||
// }) |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
} |
||||
|
||||
class KeyBoardView:UITextField{ |
||||
|
||||
} |
||||
|
||||
struct SendView_Previews: PreviewProvider { |
||||
static var previews: some View { |
||||
SendView() |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
// |
||||
// TextView.swift |
||||
// SwiftUITextViewDemo |
||||
// |
||||
// Created by Simon Ng on 7/5/2020. |
||||
// Copyright © 2020 AppCoda. All rights reserved. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
struct MultiLineTextView: UIViewRepresentable { |
||||
|
||||
@Binding var text: String |
||||
@Binding var textStyle: UIFont.TextStyle |
||||
|
||||
func makeUIView(context: Context) -> UITextView { |
||||
let textView = UITextView() |
||||
|
||||
textView.delegate = context.coordinator |
||||
textView.font = UIFont.preferredFont(forTextStyle: textStyle) |
||||
textView.autocapitalizationType = .sentences |
||||
textView.isSelectable = true |
||||
textView.isUserInteractionEnabled = true |
||||
|
||||
return textView |
||||
} |
||||
|
||||
func updateUIView(_ uiView: UITextView, context: Context) { |
||||
uiView.text = text |
||||
uiView.font = UIFont.preferredFont(forTextStyle: textStyle) |
||||
} |
||||
|
||||
func makeCoordinator() -> Coordinator { |
||||
Coordinator($text) |
||||
} |
||||
|
||||
class Coordinator: NSObject, UITextViewDelegate { |
||||
var text: Binding<String> |
||||
|
||||
init(_ text: Binding<String>) { |
||||
self.text = text |
||||
} |
||||
|
||||
func textViewDidChange(_ textView: UITextView) { |
||||
self.text.wrappedValue = textView.text |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue