更新个人界面

master
hua 4 years ago
parent 6cccb75b0c
commit 5a79705fa5
  1. 24
      Weibo.xcodeproj/project.pbxproj
  2. 26
      Weibo.xcworkspace/xcuserdata/qihuapan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
  3. 1
      Weibo/AppDelegate.swift
  4. 21
      Weibo/Assets.xcassets/arrow-right.imageset/Contents.json
  5. BIN
      Weibo/Assets.xcassets/arrow-right.imageset/arrow-right.png
  6. 21
      Weibo/Assets.xcassets/crown.imageset/Contents.json
  7. BIN
      Weibo/Assets.xcassets/crown.imageset/crown.png
  8. 21
      Weibo/Assets.xcassets/earth.imageset/Contents.json
  9. BIN
      Weibo/Assets.xcassets/earth.imageset/earth.png
  10. 21
      Weibo/Assets.xcassets/location.imageset/Contents.json
  11. BIN
      Weibo/Assets.xcassets/location.imageset/location.png
  12. 36
      Weibo/ContentView.swift
  13. 64
      Weibo/GrowinTextView/GrowingTextInputView.swift
  14. 72
      Weibo/GrowinTextView/TextViewWrapper.swift
  15. 50
      Weibo/IndexView.swift
  16. 34
      Weibo/Info.plist
  17. 84
      Weibo/LoginView.swift
  18. 162
      Weibo/SendView.swift
  19. 48
      Weibo/TextView.swift
  20. 8
      Weibo/Weibo.xcdatamodeld/Weibo.xcdatamodel/contents

@ -8,6 +8,10 @@
/* Begin PBXBuildFile section */
43F5631C74EF810F4F999A66 /* Pods_WeiboTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 11A13FDA013FB0DA2E12E48F /* Pods_WeiboTests.framework */; };
7153B8FC24EDCB0D00D9C7E3 /* SendView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7153B8FB24EDCB0D00D9C7E3 /* SendView.swift */; };
7153B90024EDDFCE00D9C7E3 /* TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7153B8FF24EDDFCE00D9C7E3 /* TextView.swift */; };
7153B90624EDF5B200D9C7E3 /* GrowingTextInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7153B90424EDF5B200D9C7E3 /* GrowingTextInputView.swift */; };
7153B90724EDF5B200D9C7E3 /* TextViewWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7153B90524EDF5B200D9C7E3 /* TextViewWrapper.swift */; };
716E9F0224E96288002CC6B8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 716E9F0124E96288002CC6B8 /* AppDelegate.swift */; };
716E9F0424E96288002CC6B8 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 716E9F0324E96288002CC6B8 /* SceneDelegate.swift */; };
716E9F0724E96288002CC6B8 /* Weibo.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 716E9F0524E96288002CC6B8 /* Weibo.xcdatamodeld */; };
@ -44,6 +48,10 @@
11A13FDA013FB0DA2E12E48F /* Pods_WeiboTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WeiboTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
27B0BA649924BF20ED711CE6 /* Pods-Weibo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Weibo.debug.xcconfig"; path = "Target Support Files/Pods-Weibo/Pods-Weibo.debug.xcconfig"; sourceTree = "<group>"; };
6808829B1FA2E4D6EA25A6AA /* Pods-WeiboTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WeiboTests.release.xcconfig"; path = "Target Support Files/Pods-WeiboTests/Pods-WeiboTests.release.xcconfig"; sourceTree = "<group>"; };
7153B8FB24EDCB0D00D9C7E3 /* SendView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendView.swift; sourceTree = "<group>"; };
7153B8FF24EDDFCE00D9C7E3 /* TextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; };
7153B90424EDF5B200D9C7E3 /* GrowingTextInputView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GrowingTextInputView.swift; sourceTree = "<group>"; };
7153B90524EDF5B200D9C7E3 /* TextViewWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextViewWrapper.swift; sourceTree = "<group>"; };
716E9EFE24E96288002CC6B8 /* Weibo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Weibo.app; sourceTree = BUILT_PRODUCTS_DIR; };
716E9F0124E96288002CC6B8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
716E9F0324E96288002CC6B8 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@ -115,6 +123,15 @@
path = Pods;
sourceTree = "<group>";
};
7153B90324EDF5B200D9C7E3 /* GrowinTextView */ = {
isa = PBXGroup;
children = (
7153B90424EDF5B200D9C7E3 /* GrowingTextInputView.swift */,
7153B90524EDF5B200D9C7E3 /* TextViewWrapper.swift */,
);
path = GrowinTextView;
sourceTree = "<group>";
};
716E9EF524E96288002CC6B8 = {
isa = PBXGroup;
children = (
@ -140,6 +157,8 @@
716E9F0024E96288002CC6B8 /* Weibo */ = {
isa = PBXGroup;
children = (
7153B90324EDF5B200D9C7E3 /* GrowinTextView */,
7153B8FF24EDDFCE00D9C7E3 /* TextView.swift */,
716E9F0124E96288002CC6B8 /* AppDelegate.swift */,
716E9F0324E96288002CC6B8 /* SceneDelegate.swift */,
716E9F0824E96288002CC6B8 /* ContentView.swift */,
@ -152,6 +171,7 @@
716E9F3B24EABF1D002CC6B8 /* Weibo-Brigding-Header.h */,
716E9F4124EB077E002CC6B8 /* UserData.swift */,
716E9F4324EB1E04002CC6B8 /* IndexView.swift */,
7153B8FB24EDCB0D00D9C7E3 /* SendView.swift */,
);
path = Weibo;
sourceTree = "<group>";
@ -436,10 +456,14 @@
files = (
716E9F4424EB1E04002CC6B8 /* IndexView.swift in Sources */,
716E9F4224EB077E002CC6B8 /* UserData.swift in Sources */,
7153B90724EDF5B200D9C7E3 /* TextViewWrapper.swift in Sources */,
716E9F0224E96288002CC6B8 /* AppDelegate.swift in Sources */,
716E9F0424E96288002CC6B8 /* SceneDelegate.swift in Sources */,
716E9F0924E96288002CC6B8 /* ContentView.swift in Sources */,
716E9F3924EA9175002CC6B8 /* LoginView.swift in Sources */,
7153B90624EDF5B200D9C7E3 /* GrowingTextInputView.swift in Sources */,
7153B90024EDDFCE00D9C7E3 /* TextView.swift in Sources */,
7153B8FC24EDCB0D00D9C7E3 /* SendView.swift in Sources */,
716E9F0724E96288002CC6B8 /* Weibo.xcdatamodeld in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

@ -7,32 +7,16 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "9FABDFDE-B9D8-48F0-B5D0-5DCD4C2A0E17"
uuid = "BCC44577-FDE6-4D8E-9A19-DCC32484D3A0"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Weibo/AppDelegate.swift"
filePath = "Pods/Alamofire/Source/Session.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "25"
endingLineNumber = "25"
landmarkName = "didReceiveWeiboResponse(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "D69CB787-5F8B-4855-A65B-395213D2A2AA"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Weibo/LoginView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "39"
endingLineNumber = "39"
landmarkName = "loadUserInfo()"
startingLineNumber = "275"
endingLineNumber = "275"
landmarkName = "request(_:method:parameters:encoding:headers:interceptor:requestModifier:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>

@ -24,7 +24,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate,WeiboSDKDelegate,WBHttpReq
//
if response is WBAuthorizeResponse{
if let res=response as? WBAuthorizeResponse{
// let message = ": \(res.statusCode)\nresponse.accessToken: \(res.accessToken)\nUserInfo: \(res.userInfo)\nUserInfo: \(res.requestUserInfo)\nuserID:\(res.userID)"
// print(message)
let user = UserData.getUser()
user.access_token=res.accessToken

@ -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
}
}

Binary file not shown.

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
}
}

Binary file not shown.

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
}
}

Binary file not shown.

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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

@ -8,23 +8,39 @@
import SwiftUI
import CoreData
struct ContentView: View {
@State var selection=1
@Environment(\.managedObjectContext) var contenxt:NSManagedObjectContext
@EnvironmentObject var user:User
@State var selection=2
var body: some View {
TabView(selection: self.$selection) {
IndexView().tabItem { VStack {
Image("house")
Text("首页")
.foregroundColor(Color.black)
} }.tag(1)
if self.user.access_token==nil{
IndexView().tabItem { VStack {
Image("house")
Text("首页")
.foregroundColor(Color.black)
} }.tag(1).hidden()
}else{
IndexView().tabItem { VStack {
Image("house")
Text("首页")
.foregroundColor(Color.black)
} }.tag(1)
}
LoginView().tabItem { VStack {
Image("user")
Text("")
} }.tag(2)
Image("user")
Text("")
} }.tag(2)
}
}
}

@ -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

@ -57,9 +57,11 @@ struct TopView:View {
@Binding var icon: String
@State var activeMenu:String="全部关注"
@State var activeMenu:String="最新微博"
@State var menuIndex=0
@Binding var isSend:Bool
var body: some View{
VStack {
@ -98,7 +100,9 @@ struct TopView:View {
Spacer()
HStack(){
Image("red packet")
Image("edit")
Image("edit").onTapGesture(perform: {
self.isSend=true
})
}
.padding(.trailing, 18.0)
.frame(width: nil)
@ -336,6 +340,10 @@ struct IndexView: View {
@State var angle:Double=0
@State var isSend=false
@State var showTip=true
func tansformDate(dateStr:String)->String{
let formatter = DateFormatter()
@ -347,11 +355,14 @@ struct IndexView: View {
let date = Date(timeIntervalSince1970: unix!)
return formatter.string(from: date)
}
func loadContent(){
self.showTip=true
if let access_token=self.user.access_token{
print("加载用户\(String(describing: self.user.uid))关注用户的最新微博")
AF.request("https://api.weibo.com/2/statuses/friends_timeline.json",parameters: ["access_token":access_token]).responseJSON { response in
self.showTip=false
if let data=response.data,let json = try? JSON(data: data){
if let statuses = json["statuses"].array {
self.statuses.removeAll()
@ -376,36 +387,45 @@ struct IndexView: View {
}
print("解析\(self.statuses.count)条微博数据")
}else{
print("loadUserInfo error")
print("loadUserInfo error:\(response.error)")
}
}
}
}else{
print("加载公共微博")
}
}
var body: some View {
VStack {
TopView(icon: $icon).onAppear(perform: {
self.loadContent()
})
if self.statuses.count>0{
if self.isSend{
SendView(flag: {
self.isSend=false
})
}else{
TopView(icon: $icon, isSend: self.$isSend).onAppear(perform: {
self.loadContent()
})
if self.showTip{
Spacer()
LoadView()
Spacer()
}
List(self.statuses){
data in
RowView(content: data)
}
}else{
Spacer()
LoadView()
Spacer()
}.onAppear(perform: {
self.showTip=false
})
}
}
}
}

@ -2,22 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>appkey</key>
<string>568392886</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>sinaweibo</string>
<string>sinaweibohd</string>
<string>sinaweibosso</string>
<string>sinaweibohdsso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
@ -41,14 +25,28 @@
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>wb568392886</string>
<string>wb1946444944</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>sinaweibo</string>
<string>sinaweibohd</string>
<string>sinaweibosso</string>
<string>sinaweibohdsso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
@ -95,5 +93,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>appkey</key>
<string>1946444944</string>
</dict>
</plist>

@ -10,9 +10,6 @@ import SwiftUI
import CoreData
import SwiftyJSON
import Alamofire
struct UserProfile {
var name:String?
}
struct LoginView: View {
@ -20,10 +17,9 @@ struct LoginView: View {
@EnvironmentObject var user:User
@State var userInfo=UserProfile()
let queue=OperationQueue()
@State var showView=false
func login() {
let request=WBAuthorizeRequest()
@ -33,10 +29,25 @@ struct LoginView: View {
func loadUserInfo(){
print("toekn=\(self.user.access_token),date=\(self.user.expiration_Date)")
self.showView=false
AF.request("https://api.weibo.com/2/users/show.json",parameters: ["access_token":self.user.access_token,"uid":self.user.uid]).responseJSON { response in
if let data=response.data,let json = try? JSON(data: data){
print(json)
if let name=json["name"].string,
let avatar_hd=json["avatar_hd"].string,
let desc=json["description"].string,
let statuses_count=json["statuses_count"].int32,
let friends_count=json["friends_count"].int32,
let followers_count=json["followers_count"].int32{
self.user.name=name
self.user.avatar_hd=avatar_hd
self.user.desc=desc
self.user.statuses_count=statuses_count
self.user.friends_count=friends_count
self.user.followers_count=followers_count
UserData.saveContext()
self.showView=true
}
}else{
print("loadUserInfo error")
}
@ -57,22 +68,71 @@ struct LoginView: View {
self.login()
})
}
else if self.userInfo.name==nil{
else if self.showView{
UserView()
}else{
Text("正在获取用户信息").onAppear(perform: {
self.loadUserInfo()
self.loadUserInfo()
})
}else{
Text("username=\(self.userInfo.name!)")
}
}
}
}
struct UserView:View {
@EnvironmentObject var user:User
var body:some View{
VStack {
HStack {
ImageView(imageUrl: self.user.avatar_hd!)
.frame(width: 60.0, height: 60.0)
.clipShape(/*@START_MENU_TOKEN@*/Circle()/*@END_MENU_TOKEN@*/)
VStack {
Text(self.user.name!)
Text("简介:\(self.user.desc!)")
}
Spacer()
Button(action: {
print("会员")
}) {
HStack(spacing:0) {
Image("crown")
Text("会员")
Image("arrow-right")
}
}
}
Rectangle()
.frame(height: 1)
HStack(spacing: 100.0){
VStack{
Text("\(self.user.statuses_count)")
Text("微博")
}
VStack{
Text("\(self.user.friends_count)")
Text("关注")
}
VStack{
Text("\(self.user.followers_count)")
Text("粉丝")
}
}
.padding(.horizontal, 20.0)
Rectangle()
.frame(height: 10)
.foregroundColor(Color(red: 220/255, green: 220/255, blue: 220/255, opacity: 1.0))
}
}
}
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
LoginView().environment(\.managedObjectContext, UserData.getContext()).environmentObject(UserData.getUser())
// LoginView().environment(\.managedObjectContext, UserData.getContext()).environmentObject(UserData.getUser())
UserView()
}
}

@ -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
}
}
}

@ -2,11 +2,17 @@
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="16119" systemVersion="19G73" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="User" representedClassName=".User" syncable="YES" codeGenerationType="class">
<attribute name="access_token" optional="YES" attributeType="String"/>
<attribute name="avatar_hd" optional="YES" attributeType="String"/>
<attribute name="desc" optional="YES" attributeType="String"/>
<attribute name="expiration_Date" optional="YES" attributeType="Double" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="followers_count" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="friends_count" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="refresh_token" optional="YES" attributeType="String"/>
<attribute name="statuses_count" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="uid" optional="YES" attributeType="String"/>
</entity>
<elements>
<element name="User" positionX="-63" positionY="-18" width="128" height="103"/>
<element name="User" positionX="-63" positionY="-18" width="128" height="193"/>
</elements>
</model>
Loading…
Cancel
Save