Interface switching
In the project, you can put the interface with a high degree of coupling in a StoryBoard. You can use multiple StoryBoards to build interfaces according to functions. This is convenient for project maintenance and multi-person development. For switching between multiple StoryBoards, you can use the following code:
@IBAction func ChangeOne (sender: UIButton) {
var oneStoryBoard: UIStoryboard = UIStoryboard (name: "One", bundle: NSBundle.mainBundle ())
let oneController: UIViewController = oneStoryBoard.instantiateViewControllerWithIdentifier ("oneId") as UIViewController
self.navigationController? .pushViewController (oneController, animated: true)
}
It should be noted that the above "One" is One.storyboard, and "oneId" is the Storyboard ID in
Another thing to note is that the main interface of the switch interface must be Navigation Contoller
UIScrollView realize picture carousel
//
// Two.swift
// MultStoryBoardChanged
//
// Created by System Administrator on 15/2/6.
// Copyright (c) 2015 jwzhangjie. All rights reserved.
//
import UIKit
class Two: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scrollview: UIScrollView!
@IBOutlet weak var pageControl: UIPageControl!
var timer: NSTimer!
override func viewDidLoad () {
super.viewDidLoad ();
// image width
let imageW: CGFloat = self.scrollview.frame.size.width;
let imageH: CGFloat = self.scrollview.frame.size.height;
var imageY: CGFloat = 0;
var totalCount: NSInteger = 5;
for index in 0 .. <totalCount {
var imageView: UIImageView = UIImageView ();
let imageX: CGFloat = CGFloat (index) * imageW;
imageView.frame = CGRectMake (imageX, imageY, imageW, imageH);
let name: NSString = NSString (format: "image_0% d", index + 1);
imageView.image = UIImage (named: name);
self.scrollview.showsHorizontalScrollIndicator = false;
self.scrollview.addSubview (imageView);
}
let contentW: CGFloat = imageW * CGFloat (totalCount);
self.scrollview.contentSize = CGSizeMake (contentW, 0);
self.scrollview.pagingEnabled = true;
self.scrollview.delegate = self;
self.pageControl.numberOfPages = totalCount;
self.addTimer ()
}
func nextImage (sender: AnyObject!) {
var page: Int = self.pageControl.currentPage;
if (page == 4) {
page = 0;
} else {
++ page;
}
let x: CGFloat = CGFloat (page) * self.scrollview.frame.size.width;
self.scrollview.contentOffset = CGPointMake (x, 0);
}
func scrollViewDidScroll (scrollView: UIScrollView) {
let scrollviewW: CGFloat = scrollview.frame.size.width;
let x: CGFloat = scrollview.contentOffset.x;
let page: Int = (Int) ((x + scrollviewW / 2) / scrollviewW);
self.pageControl.currentPage = page;
}
func scrollViewWillBeginDragging (scrollView: UIScrollView) {
self.removeTimer ();
}
func scrollViewDidEndDragging (scrollView: UIScrollView, willDecelerate decelerate: Bool) {
self.addTimer ();
}
func addTimer () {
self.timer = NSTimer.scheduledTimerWithTimeInterval (1, target: self, selector: "nextImage:", userInfo: nil, repeats: true);
NSRunLoop.currentRunLoop (). AddTimer (self.timer, forMode: NSRunLoopCommonModes);
}
func removeTimer () {
self.timer.invalidate ();
}
}
It should be noted that in XCode6.1
for index in 0 .. <totalCount {
0 .. <is a half interval, the header is not the tail ... the entire interval
Swift basics--Switch between StoryBoard and UIScrollView control to realize picture carousel