ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef nameArray = ABAddressBookCopyArrayOfAllPeople (addressBook);
m_SourceContactsUserArray = [[NSMutableArray alloc] init];
for (int i = 0; i<CFArrayGetCount(nameArray); i++) {
ABRecordRef person = CFArrayGetValueAtIndex(nameArray, i);
NSString *personName = (NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);
[m_SourceContactsUserArray addObject:personName];
}
CFRelease(addressBook);
CFRelease(nameArray);
Run Code Online (Sandbox Code Playgroud) 我要修剪视频文件。我只想从图库中选择视频并将其转换为15秒的视频。我正在使用Objective C的此 链接。它对我来说很好用,但我是Swift语言的初学者。谁能帮助我在Swift中转换此代码?
以下是我在Objective C中的代码:
-(void)cropVideo:(NSURL*)videoToTrimURL{
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoToTrimURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *outputURL = paths[0];
NSFileManager *manager = [NSFileManager defaultManager];
[manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil];
outputURL = [outputURL stringByAppendingPathComponent:@"output.mp4"];
// Remove Existing File
[manager removeItemAtPath:outputURL error:nil];
//
exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTime start = CMTimeMakeWithSeconds(1.0, 600); // you will modify time range here
CMTime duration = CMTimeMakeWithSeconds(19.0, 600); …Run Code Online (Sandbox Code Playgroud) Though application is universal but ipad screen is blank. I have added checked both iphone and ipad. When running app in iphone works fine, but in ipad is not showing anything.
struct UserListView: View {
var userName:String
@State var searchString:String = ""
var body: some View {
VStack {
SearchBar(text: $searchString)
.padding()
.frame(height:44)
.foregroundColor(Color.white)
.background(Color.gray)
List(userList) { user in
NavigationLink(destination:UserDetailView(userObj:user)) {
UserListRow(userObj: user)
}.navigationBarTitle("User Detail")
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试从登录视图推送到详细信息视图,但无法做到这一点。即使导航栏也未显示在登录视图中。如何在swiftUI中按下按钮单击?如何在单击按钮时使用导航链接?
var body: some View {
NavigationView {
VStack(alignment: .leading) {
Text("Let's get you signed in.")
.bold()
.font(.system(size: 40))
.multilineTextAlignment(.leading)
.frame(width: 300, height: 100, alignment: .topLeading)
.padding(Edge.Set.bottom, 50)
Text("Email address:")
.font(.headline)
TextField("Email", text: $email)
.frame(height:44)
.accentColor(Color.white)
.background(Color(UIColor.darkGray))
.cornerRadius(4.0)
Text("Password:")
.font(.headline)
SecureField("Password", text: $password)
.frame(height:44)
.accentColor(Color.white)
.background(Color(UIColor.darkGray))
.cornerRadius(4.0)
Button(action: {
print("login tapped")
}) {
HStack {
Spacer()
Text("Login").foregroundColor(Color.white).bold()
Spacer()
}
}
.accentColor(Color.black)
.padding()
.background(Color(UIColor.darkGray))
.cornerRadius(4.0)
.padding(Edge.Set.vertical, 20)
}
.padding(.horizontal,30)
}
.navigationBarTitle(Text("Login"))
}
Run Code Online (Sandbox Code Playgroud)
我只是在滚动视图中添加了 TextLabel,但它仅显示在 1 行中。没有滚动视图,它可以在 Label 的全高度下正常工作
struct UserDetailView: View {
var userObj:User?
var body: some View {
ScrollView {
VStack {
Text("Hi here is Erick jackson. We need to help you. We will help you. Anything new to learn from you. I am here for that reason.")
.background(Color.orange)
.multilineTextAlignment(.center)
.lineLimit(5)
}
}
.padding(.horizontal,30)
}
}
Run Code Online (Sandbox Code Playgroud)