我想要像幻灯片一样显示3D模型。当你点击下一个时,下一个出现它的动画几秒钟....然后下一个....然后继续改变UILabel文本。
PressedNextbtn ---> (在ARSCNView上)新的3D模型显示---> PressedNextbtn ---> (在ARSCNView上)新的3D模型显示--->
此外,我想添加一个上一个按钮,以便它也可以返回。如果不清楚,请查看下面的图片以获取更多信息。
所以:
注意:我已经找到了UILabel,现在我需要将3D模型幻灯片放映到图像中看到的系统。我希望这能澄清一切。
@IBAction func nextPressed(_ sender: Any) {
displayNext()
//从阵列中显示NEXT 3D模型固有的动画 }
@IBAction func prevPressed(_ sender: Any) {
getPrevious()
// DISPLAY以前具有固有动画的3D模型 }
func displayNext() {
guard currentIndex < myArray.count else {
// timer.invalidate() //if you don't want to repeat showing the images you can invalidate the timer.
currentIndex = 0 // add this if you want to repeat showing the image
return
}
allArray.append(myArray[currentIndex])
sildeText.text = myArray[currentIndex]
currentIndex += 1
}
func getPrevious() {
if allArray.count > 1 {
allArray.removeLast()
sildeText.text = allArray.last
}
else {
sildeText.text = allArray.last
}
}
请检查应用程序结构.. 3D模型尚未正确定位。
答案 0 :(得分:0)
有两种方法可以实现此行为,
UIPageviewController
并在内容中添加您的UILabel和3D模型,并在&#39;下一步&#39;更改页面索引。或者&#39;以前的&#39;按钮点击。UIScrollView
并在&#39;下一步&#39;上更改框架以及UILabel和3D模型。或者&#39;以前的&#39;按钮点击。我更喜欢使用UIPageviewController
,
在ViewController.m中,
@interface ViewController () <UIPageViewControllerDataSource, UIPageViewControllerDelegate>
@property (nonatomic,strong) UIPageViewController *PageViewController;
@property (nonatomic, strong) NSArray *arrPageTitles;
@property (nonatomic, strong) NSArray *arrPageDescription;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Create page view controller
self.PageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
self.PageViewController.dataSource = self;
self.PageViewController.delegate = self;
self.shouldShowPageController = YES;
[self addChildViewController:PageViewController];
[self.view addSubview:PageViewController.view];
[self.PageViewController didMoveToParentViewController:self];
}
#pragma mark - Page View Datasource Methods
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
NSUInteger index = ((PageContentVC *) viewController).pageIndex;
if (index == NSNotFound) {
return nil;
}
if (index == 0) {
return [self viewControllerAtIndex:([self.arrPageTitles count] - 1)];
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
NSUInteger index = ((PageContentVC *) viewController).pageIndex;
if (index == NSNotFound){
return nil;
}
index++;
if (index == [self.arrPageTitles count]){
return [self viewControllerAtIndex:0];
}
return [self viewControllerAtIndex:index];
}
#pragma mark - PageContent View Controller Method
- (PageContentVC *)viewControllerAtIndex:(NSUInteger)index{
if (([self.arrPageTitles count] == 0) || (index >= [self.arrPageTitles count])) {
return nil;
}
// Create a new view controller and pass suitable data.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"PageContentVC" bundle:[NSBundle mainBundle]];
PageContentVC *pageContentViewController = [storyboard instantiateViewControllerWithIdentifier:@"PageContent"];
pageContentViewController.title = self.arrPageImages[index];
pageContentViewController.description = self.arrPageTitles[index];
pageContentViewController.pageIndex = index;
return pageContentViewController;
}
@end
这里,PageContentVC是UIPageviewController
答案 1 :(得分:0)
在viewDidLoad()方法中将数据设置为object。
override func viewDidLoad()
{
super.viewDidLoad()
imageView.image = UIImage(named: strPhotoName)
lblTitle.text = strTitle
}
实施UIPageViewController
创建两个NSArray来存储图像标题和图像名称
var arrPageTitle: NSArray = NSArray()
var arrPagePhoto: NSArray = NSArray()
变量初始化 初始化数组。
设置PageViewController的数据源。
从viewDidLoad()方法设置PageViewController的第一页。
override func viewDidLoad() {
super.viewDidLoad()
arrPageTitle = ["This is The App Guruz", "This is Table Tennis 3D", "This is Hide Secrets"];
arrPagePhoto = ["1.jpg", "2.jpg", "3.jpg"];
self.dataSource = self
self.setViewControllers([getViewControllerAtIndex(0)] as [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}
实施数据源方法
viewControllerBeforeViewController() 使用此方法返回上一个视图。在这里我提出了一个条件,如果它是第一个视图然后返回nil否则返回ViewController。
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?
{
let pageContent: PageContentViewController = viewController as! PageContentViewController
var index = pageContent.pageIndex
if ((index == 0) || (index == NSNotFound))
{
return nil
}
index--;
return getViewControllerAtIndex(index)
}
viewControllerAfterViewController 使用此方法返回下一个视图。在这里我提出了一个条件,如果它是最后一个视图然后返回nil否则返回ViewController。
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController?
{
let pageContent: PageContentViewController = viewController as! PageContentViewController
var index = pageContent.pageIndex
if (index == NSNotFound)
{
return nil;
}
index++;
if (index == arrPageTitle.count)
{
return nil;
}
return getViewControllerAtIndex(index)
}
创建获取新PageContentViewController的方法
getViewControllerAtIndex 当用户使用手势滑动时,我们必须从故事板中实例化ViewController并分配ViewController的所有内容数据并将其返回。
func getViewControllerAtIndex(index: NSInteger) -> PageContentViewController
{
// Create a new view controller and pass suitable data.
let pageContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageContentViewController") as! PageContentViewController
pageContentViewController.strTitle = "\(arrPageTitle[index])"
pageContentViewController.strPhotoName = "\(arrPagePhoto[index])"
pageContentViewController.pageIndex = index
return pageContentViewController
}